hiexam
microsoft · AI-102 · Q276 · code_completion · speech_translation, azure_sdk, python

Complete the following Python function to correctly configure and utilize the Speech Translation SDK:

Complete the following Python function to correctly configure and utilize the Speech Translation SDK:
speech_key = os.environ['SPEECH__SUBSCRIPTION__KEY']
service_region = os.environ['SPEECH__SERVICE__REGION']
def translate_speech():
    translation_config = speechsdk.translation.SpeechTranslationConfig(
        subscription=speech_key, region=service_region)
    translation_config.speech_recognition_language = {{slot1}}

    languages = {{slot2}}
    for language in languages:
        translation_config.add_target_language(language)
    audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
    recognizer = speechsdk.translation.{{slot3}}(
        speech_config=translation_config, audio_config=audio_config)

    result = recognizer.recognize_once()
    if result.reason == speechsdk.ResultReason.TranslatedSpeech:
        append_to_transcript_file(result.text, "en")
        for language in result.translations:
            append_to_transcript_file(result.translations[language], language)
Correct slot values

Answer hidden

Unlock AI-102

First 5 questions of every exam are free. Unlock the rest.

Includes
  • · All — questions
  • · Verified answers + AI explanations
  • · Spaced-repetition mistake notebook
  • · Phone, tablet, laptop sync

One-time payment. Doesn't auto-renew. · Already paid? Sign in