Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 23 of 30
❮Prev Next❯

Build an App with Azure Speech in Foundry Tools

Module 2: Microsoft Foundry ⏱ 9 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    A lightweight speech app uses Azure Speech in Foundry Tools through the Speech SDK (pip package azure-cognitiveservices-speech). You create a SpeechConfig with your key and endpoint, then use a SpeechRecognizer to turn a WAV file or the microphone into text (speech to text), and a SpeechSynthesizer with a neural voice to turn text into audio (text to speech). SSML lets you control rate, pitch, pauses and speaking style.

    Simulate it » No Azure account needed

    Exam objective: 2.2.3 Build a lightweight application by using Azure Speech in Foundry Tools. (Skills measured as of April 15, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Speech to text and text to speech Pick a voice, tweak it with SSML and copy the code.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Open <strong>Azure Speech</strong>, upload audio and <strong>transcribe</strong>. Diarization labels who spoke when.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Open Azure Speech, upload audio and transcribe. Diarization labels who spoke when.
    2. Speech to text returns the words with timestamps (and translation if you ask for it).
    3. Now the other way: type text, pick a neural voice (Indian English here) and play it.
    4. SSML controls emphasis, pauses and speed. View code shows the Speech SDK calls.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    Your kiosk app needs to listen and talk back.

    😊 THE SOLUTION

    The Speech SDK for recognition and neural voices.

    • Can’t hear users✓ SpeechRecognizer
    • Can’t speak✓ SpeechSynthesizer
    • Voice sounds rushed✓ SSML prosody
    🛠️ Solved with: Speech SDK

    Start with a question

    How does a railway announcement app know how to say 'platform 4' in a calm, clear voice?

    Station announcements used to be recorded by a person, one clip per train. Change the platform and someone had to record it again.

    Today an app can take the text “The 6:40 Chennai Express will arrive on platform 4” and speak it in a natural voice, in English or Hindi, slower for the platform number. And it can do the reverse too, turning a passenger’s spoken question into text. That’s Azure Speech.

    Explain it like I’m 10

    The technical explanation

    Azure Speech in Foundry Tools is available on your Foundry resource (or a standalone Speech resource). Your app needs the key and endpoint, which you’ll find on the resource in the Azure portal or Foundry portal.

    FeatureWhat it doesSDK piece
    Speech to text (real time)Transcribes a file or live microphoneSpeechRecognizer
    Fast and batch transcriptionTranscribes long or many recordingsREST APIs
    Text to speechSpeaks text with a neural voiceSpeechSynthesizer
    SSMLControls voice, rate, pitch, pauses, stylespeak_ssml_async
    Speech translationSpoken input to translated text or speechTranslationRecognizer
    Speaker diarizationLabels who spoke whenTranscription options
    pip install azure-cognitiveservices-speech
    export SPEECH_KEY="<key>"
    export ENDPOINT="https://<resource-name>.cognitiveservices.azure.com/"

    speech_app.py: speech to text

    import os
    import azure.cognitiveservices.speech as speechsdk
    
    speech_config = speechsdk.SpeechConfig(subscription=os.environ["SPEECH_KEY"], endpoint=os.environ["ENDPOINT"])
    speech_config.speech_recognition_language = "en-IN"
    
    # From a file. Use AudioConfig(use_default_microphone=True) for the mic.
    audio_config = speechsdk.audio.AudioConfig(filename="question.wav")
    recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
    
    result = recognizer.recognize_once_async().get()  # one utterance, up to about 30 seconds
    if result.reason == speechsdk.ResultReason.RecognizedSpeech:
        print("You said:", result.text)
    elif result.reason == speechsdk.ResultReason.NoMatch:
        print("No speech could be recognised.")

    recognize_once stops at the first pause. For a long meeting recording, use continuous recognition (start_continuous_recognition with a recognized event handler) or batch transcription.

    Text to speech with a neural voice

    speech_config.speech_synthesis_voice_name = "en-IN-NeerjaNeural"
    # Save to a file. Leave audio_config out to play on the default speaker.
    file_out = speechsdk.audio.AudioOutputConfig(filename="answer.wav")
    synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=file_out)
    
    result = synthesizer.speak_text_async("Your train will arrive on platform 4.").get()
    if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
        print("Saved answer.wav")

    SSML for control

    Plain text uses the voice’s defaults. SSML lets you slow a number down, add a pause, or pick a style that the voice supports.

    ssml = """
    <speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis"
           xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US">
      <voice name="en-US-AriaNeural">
        <mstts:express-as style="customerservice">
          Your booking is confirmed.<break time="500ms"/>
          Your PNR is <prosody rate="-30%">4 5 2 1 9 8 7 6 3 0</prosody>.
        </mstts:express-as>
      </voice>
    </speak>"""
    synthesizer.speak_ssml_async(ssml).get()

    Not every voice supports every style, so check the voice list in the Speech playground before you rely on one.

    Architect level Custom speech and custom voice

    Custom speech trains recognition on your own audio and text so it gets domain words right, like drug names or station names. Custom neural voice and personal voice create a voice that sounds like a specific person; those are limited access features with an application and consent requirements, because a cloned voice can be misused. That’s responsible AI showing up as product policy.

    Real-world business scenario

    Transport

    Contoso Rail Services

    The problem
    Platform changes meant re-recording announcements by hand, and the help kiosk couldn't understand spoken questions from travellers.
    What they used
    A Python service with the Speech SDK: SpeechSynthesizer with en-IN and hi-IN neural voices and SSML to slow down train numbers, plus SpeechRecognizer on the kiosk microphone.
    Why that choice
    Neural voices sound natural in both languages, SSML makes numbers clear on noisy platforms, and the same SDK handles listening and speaking.
    The result
    Announcements update the moment the timetable changes, and kiosk users can simply ask 'Which platform for Madurai?'.

    When to use it and when not to

    ✓ Use it when…

    • You need transcripts of calls, meetings or voice notes.
    • Your app must speak with a natural voice, in a chosen language and style.
    • You need fine control of pronunciation, pauses and speed through SSML.

    ✕ Think twice when…

    • You only want a model to answer a spoken question. An audio-capable multimodal model may be one step simpler.
    • Cloning a real person's voice without the limited-access approval and their consent.

    ↔ Alternatives to consider

    • An audio-capable multimodal model that takes input_audio directly.
    • Content Understanding for transcripts plus summaries of recorded calls.
    • Voice Live API for live voice agents.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AI-901 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    You are building a Python application that transcribes a WAV file by using the Speech SDK. Which class should you use?

    Question 2

    Question 2 of 5

    A railway application reads booking confirmations aloud. Users report that the ten-digit booking reference is spoken too quickly. You must slow down only the reference number.

    What should you use?

    Question 3

    Question 3 of 5

    An application calls recognize_once_async on a ten-minute recording and returns only the first sentence. What should you use instead?

    Question 4

    Question 4 of 5 · Select 2

    Which TWO settings can you configure on a SpeechConfig object in the Speech SDK?

    Question 5

    Question 5 of 5

    A company wants an application to read product announcements aloud in a natural, human-like voice in Hindi. Which capability should it use?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner What are the two main things Azure Speech does?

    Model answer

    Speech to text, which turns spoken audio into a transcript, and text to speech, which reads text aloud in a natural neural voice. It also does speech translation and a few more advanced features.

    Interviewer follows up

    Which Python package do you install?

    You

    azure-cognitiveservices-speech, imported as azure.cognitiveservices.speech, usually aliased to speechsdk.

    Intermediate Your recognize_once call only captures the first sentence of a five-minute recording. Why?

    Model answer

    recognize_once stops at the first pause and handles about 30 seconds at most. For longer audio I'd use continuous recognition with start_continuous_recognition and handle the recognized events, or batch transcription for big files.

    Experienced developer When do you use SSML instead of plain text for synthesis?

    Model answer

    When the defaults don't sound right: slowing down a long account number, adding a pause before a key instruction, changing pitch, using a speaking style like cheerful or customer service, or switching voices mid-paragraph. Plain text is fine for short, simple replies.

    Scenario A hospital kiosk must read discharge instructions in English and Hindi. How would you build it?

    Model answer

    Use the Speech SDK's SpeechSynthesizer with a neural voice for each language, for example an en-IN voice and hi-IN-SwaraNeural, with SSML to slow the rate for medication names. I'd keep the text reviewed by staff, since the voice reads exactly what it's given.

    Quick revision

    Key points

    • pip install azure-cognitiveservices-speech; import azure.cognitiveservices.speech as speechsdk.
    • SpeechConfig holds the key and endpoint, plus speech_recognition_language and speech_synthesis_voice_name.
    • SpeechRecognizer + AudioConfig(filename=...) or use_default_microphone=True gives speech to text.
    • SpeechSynthesizer.speak_text_async(text).get() reads text in the chosen neural voice.
    • speak_ssml_async takes SSML to control rate, pitch, pauses and style.

    Important terminology

    Azure Speech in Foundry Tools
    The Foundry Tools service (formerly Azure AI Speech) for speech to text, text to speech, translation and voice features.
    SpeechConfig
    The Speech SDK object that holds your key, endpoint, recognition language and synthesis voice.
    SpeechRecognizer
    The Speech SDK class that converts audio from a file or microphone into text.
    SpeechSynthesizer
    The Speech SDK class that converts text or SSML into spoken audio.
    Neural voice
    A natural-sounding prebuilt voice such as en-US-AvaMultilingualNeural or en-IN-NeerjaNeural.
    SSML
    Speech Synthesis Markup Language, an XML format for controlling voice, rate, pitch, pauses and style.

    Common mistakes

    • Using recognize_once for long recordings. It stops after one utterance (about 30 seconds max).
    • Forgetting to check result.reason, so silent failures look like empty text.

    Exam tips

    • "Read text aloud in a natural voice" = text to speech with a neural voice.
    • "Make the voice pause or slow down" = SSML.
    • "Transcribe a recording" = speech to text with SpeechRecognizer.

    Five quick revision questions

    1. 1.Which class turns audio into text?Show

      SpeechRecognizer

    2. 2.Which class turns text into audio?Show

      SpeechSynthesizer

    3. 3.Which property chooses the voice?Show

      speech_config.speech_synthesis_voice_name

    4. 4.What markup controls pauses and speaking rate?Show

      SSML (Speech Synthesis Markup Language).

    5. 5.What should you use instead of recognize_once for long audio?Show

      Continuous recognition (or batch transcription).

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Use Images in Prompts with a Multimodal Model

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.