
You are developing a speech translation service for recording lectures given in English (United Kingdom). The goal is to provide transcripts in multiple target languages: English, French, Spanish, and German.
Key requirements from the code snippet:
Source Language (Recognition Language):
config.SpeechRecognitionLanguage = "en-GB";
The input is English (UK).
Target Languages:You need to define a list of supported target languages. Since English, French, Spanish, and German are supported, the correct syntax is:
var lang = new List() { "en", "fr", "de", "es" };
This uses ISO language codes expected by the Translator API ("fr" = French, "de" = German, "es" = Spanish).
Recognizer Type:Since this is speech translation, you must use:
using var recognizer = new TranslationRecognizer(config, audioConfig);
The TranslationRecognizer class is specifically for translating speech input into multiple languages.
Completed Codestatic async Task TranslateSpeechAsync()
{
var config = SpeechTranslationConfig.FromSubscription("69cad5cc-0ab3-4704-bdff-abf4aa07d85", "uksouth");
var lang = new List() { "en", "fr", "de", "es" };
config.SpeechRecognitionLanguage = "en-GB";
lang.ForEach(config.AddTargetLanguage);
using var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
using var recognizer = new TranslationRecognizer(config, audioConfig);
var result = await recognizer.RecognizeOnceAsync();
if (result.Reason == ResultReason.TranslatedSpeech)
{
foreach (var element in result.Translations)
{
AppendToTranscriptFile(element.Value, element.Key);
}
}
}
First Blank: {"en", "fr", "de", "es"}
Second Blank: TranslationRecognizer
Final Answer (Answer Area Selections)
Speech Translation with Speech SDK
TranslationRecognizer class
Speech service supported languages
Microsoft References
Submit