Let’s Get Certified
Module 06 / 08 · Implement AI solutions by using Microsoft Foundry

Build a spoken help desk

Choose text analysis, audio-capable inference or the Speech SDK and handle incomplete recognition.

Build a spoken help desk

Work through the decision

A visitor asks a spoken question. The desk needs both a verbatim transcript for correction and an answer drawn from museum policy. How would you make both outputs inspectable?

Check your reasoning

Use speech recognition with the expected locale to obtain a transcript, inspect its result status and let the visitor correct critical names. Pass the approved text and relevant policy to the answer model. For a direct response to an audio prompt, use a deployment that accepts the recording’s format and modality.

Watch the source lesson at 51:31

Compare the choices

Text analysis client
Send a text document to the intended analysis operation and inspect its per-document result. Preserve IDs so batch results map to their inputs.
Audio-capable model input
Send actual audio content in a supported representation with a task instruction to a deployment that supports audio.
Speech recognizer
Configure the Speech SDK for the locale, audio source and service resource. Inspect the recognized result before using its text.
Speech synthesizer
Supply text and voice settings and send the synthesized audio to the chosen output.
No-match handling
A completed recognition attempt can yield no recognized speech. Offer another attempt or a typed path and avoid treating silence as text.
Cancellation diagnostics
Read the cancellation details on a canceled operation and inspect the reported configuration, network or authentication error.
Recognition locale
Select the expected language or configure appropriate language detection. Test domain vocabulary and accents with representative clips.

Test the decision

Test silence, an unsupported codec and an unfamiliar exhibit name separately. A silence result should trigger a retry or a typed alternative. Log a diagnostic identifier for a canceled operation and retain raw audio only when justified.

Read a text analysis result

With the azure-ai-textanalytics package and an authorized Azure identity, build a client for the Language resource endpoint. Analyze a batch and handle each document independently. One invalid item need not hide successful siblings.

import os
from azure.ai.textanalytics import TextAnalyticsClient
from azure.identity import DefaultAzureCredential

language = TextAnalyticsClient(os.environ["LANGUAGE_ENDPOINT"],
                               DefaultAzureCredential())
documents = [{"id": "desk-17", "language": "en",
              "text": "The tour was excellent but the queue was long."}]
for item in language.analyze_sentiment(documents):
    if item.is_error:
        print(item.id, item.error.code)
    else:
        print(item.id, [(s.text, s.sentiment) for s in item.sentences])

Azure Text Analytics Python library

Recognize a short utterance

With the azure-cognitiveservices-speech package, set SPEECH_KEY and SPEECH_REGION for the same resource. Use a short supported PCM WAV file. For a spoken reply, pass approved text to a SpeechSynthesizer with the desired output device or file.

import os
import azure.cognitiveservices.speech as speech

config = speech.SpeechConfig(subscription=os.environ["SPEECH_KEY"],
                             region=os.environ["SPEECH_REGION"])
config.speech_recognition_language = "en-US"
source = speech.audio.AudioConfig(filename="question.wav")
recognizer = speech.SpeechRecognizer(speech_config=config, audio_config=source)
result = recognizer.recognize_once_async().get()
if result.reason == speech.ResultReason.RecognizedSpeech:
    print(result.text)
elif result.reason == speech.ResultReason.NoMatch:
    print("Please repeat or type your question.")
else:
    print(result.cancellation_details.reason)

Microsoft Speech quickstart

Send audio as model input

For an audio-capable Azure OpenAI Chat Completions deployment, a message can contain both an instruction and the encoded recording. This fragment assumes client is authenticated for the deployment. Request text output when the interface displays the answer.

import base64
from pathlib import Path

encoded = base64.b64encode(Path("question.wav").read_bytes()).decode("ascii")
parts = [{"type": "text", "text": "Answer the spoken visitor question."},
         {"type": "input_audio", "input_audio": {"data": encoded, "format": "wav"}}]
reply = client.chat.completions.create(model=audio_deployment,
    modalities=["text"], messages=[{"role": "user", "content": parts}])
print(reply.choices[0].message.content)

Azure audio completions

Practice the guide skills

  1. Prepare two text documents with IDs, submit them to a sentiment operation and inspect the per-document result including any error. Watch 51:31
  2. Give an audio-capable deployment a spoken request and an instruction. Compare an actual audio input with a filename supplied as plain text. Watch 52:34
  3. Configure a Speech SDK recognizer for a test clip, inspect recognized, no-match and canceled outcomes, then send an approved reply to a synthesizer. Watch 52:59

Official objectives for this lesson

Related lesson · Choose where AI belongs in a customer interaction

Knowledge check

Build a spoken help desk quiz

Answer 3 questions. Check each answer for an explanation.