Speech Translation seems not working for me

timchen 20 Reputation points

Screenshot from 2023-03-07 14-33-08.png

this is my sample code, and screenshot.

From screenshoot

[14:31:58] RECOGNIZED: Text=How are you?
[14:31:58] TRANSLATED: How are you?

TRANSLATED: How are you? -> "你好嗎". I expected the translated result is [14:31:58] TRANSLATED: 你好嗎?

That seems not to translated. Do anyone know why ?

var autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig.FromLanguages(new string[]{ "en-US", "zh-TW", "ja-JP" });

SpeechTranslationConfig config  = SpeechTranslationConfig.FromSubscription(Config.SpeechServiceSubscriptionKey, Config.SpeechServiceRegion);
config.SpeechRecognitionLanguage = "zh-TW";

print($"config.SpeechRecognitionLanguage {config.SpeechRecognitionLanguage}");
var targetLanguages = config.TargetLanguages;
foreach (var language in targetLanguages)
    print($" config.TargetLanguages  :{ language }");

pushStream = AudioInputStream.CreatePushStream(AudioStreamFormat.GetWaveFormatPCM(48000, 16, 1));

recognizer = new TranslationRecognizer(config, autoDetectSourceLanguageConfig, AudioConfig.FromStreamInput(pushStream));

recognizer.Recognized += (s, e) =>
      if (e.Result.Reason == ResultReason.TranslatedSpeech)
         Debug.Log($"RECOGNIZED: Text={e.Result.Text}");
         Debug.Log($"TRANSLATED: {e.Result.Translations["zh-Hant"]} ");
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,355 questions
0 comments No comments
{count} votes

Accepted answer
  1. romungi-MSFT 41,861 Reputation points Microsoft Employee

    timchen I think the issue here could be the setting of speech recognition language and the audo detect language config. Try using only the speech recognition language of en-US and comment out autoDetectSourceLanguageConfig and do not pass the same in TranslationRecognizer() as it is optional. Here is what I tried and it works as expected.

    User's image

    As you can see, I only used the recognition language and target language to get accurate output. You can add

    auto_detect_source_language_config to the recognizer and pass the required languages but it should be consistent with the recognition language that is actually used.

    In your snippet change the following:

    config.SpeechRecognitionLanguage = "zh-TW";


    config.SpeechRecognitionLanguage = "en-US";

    Comment out auto detection config and remove it from the recognizer and check if it works.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. timchen 20 Reputation points
    0 comments No comments