Bitzu

AI-901 ยท Text and speech solutions

Speech app with Azure Speech (Python)

Reading Python that configures a speech resource, recognizes speech from a microphone or file, synthesizes spoken audio with a chosen voice and handles results and cancellation.

Key points

  • pip install azure-cognitiveservices-speech; import azure.cognitiveservices.speech as speechsdk.
  • SpeechConfig: key and endpoint.
  • Recognition: AudioConfig(use_default_microphone=True) or AudioConfig(filename=...), SpeechRecognizer, recognize_once_async().
  • Synthesis: speech_synthesis_voice_name, SpeechSynthesizer, speak_text_async(text).
  • Check result.reason (RecognizedSpeech, NoMatch, Canceled); on Canceled read cancellation_details.

Source: https://learn.microsoft.com/en-us/azure/ai-services/speech-service/get-started-speech-to-text?pivots=programming-language-python

Practice questions

Single choice

Which PyPI package provides the Speech SDK for Python?

  1. azure-ai-textanalytics
  2. azure-cognitiveservices-speech
  3. azure-ai-projects
  4. azure-identity
Show answer

Answer: B. azure-cognitiveservices-speech

azure-cognitiveservices-speech is the Speech SDK package, imported as azure.cognitiveservices.speech. azure-ai-textanalytics is the Language client.

Select all that apply

Which pieces belong in a minimal text-to-speech script with the Speech SDK?

  1. speech_config.speech_synthesis_voice_name set to a neural voice
  2. AudioOutputConfig pointing to the default speaker or a file
  3. A check for ResultReason.SynthesizingAudioCompleted
  4. A SpeechRecognizer to produce the audio
  5. add_target_language to pick the spoken language
Show answer

Answer: A. speech_config.speech_synthesis_voice_name set to a neural voice, B. AudioOutputConfig pointing to the default speaker or a file, C. A check for ResultReason.SynthesizingAudioCompleted

You choose a voice on SpeechConfig, send the audio to a speaker or file with an output config, and check the result reason. SpeechRecognizer is for the opposite direction, and a translation target is only for translation.

True or false

recognize_once_async keeps listening and returns text for as long as the speaker talks, however long the audio is.

Show answer

Answer: False

False. It transcribes a single utterance of up to about 30 seconds or until silence; longer audio needs continuous recognition.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More AI-901 topics in this module