Azure Speech Service: Text to Speech | Microsoft AI-102 Exam Solution

Azure Speech Service: Text to Speech

Question

You plan to use Azure Speech service to convert text to speech and output it to a speaker.

First you create a speech configuration and next you synthesize speech to the speaker output.

Given that the prerequisites are met, Speech SDK is installed and required packages are included, review the code below and complete it by choosing the appropriate answer choices.

(select two options)

static async Task SynthesizeAudioAsync() { var config = ……………………………..FromSubscription("<subscription key>","<azure region>");  using var synthesizer = new …………………………...(config);  await synthesizer.SpeakTextAsync("<speaker output>"); } 

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answers: A and D

Here is the completed code snippets

&lt;pre class="brush:java;"&gt;static async Task SynthesizeAudioAsync()

{

var config = SpeechConfig.FromSubscription("&amp;lt;subscription key&amp;gt;","&amp;lt;azure region&amp;gt;");

using var synthesizer = new SpeechSynthesizer(config);

await synthesizer.SpeakTextAsync("&amp;lt;speaker output&amp;gt;");

}

&lt;/pre&gt;Option A is correct because SpeechConfig provides the key and associated azure region details that is one of the ways to initialize SpeechConfig.

The other options are to use an authorization token, pass a host address or pass a Speech service endpoint.

Option B is incorrect because the AudioConfig object is used to contain information when the output is intended to a file.

Option C is incorrect because the AudioDataStream object is used when output is intended to an in memory data stream.

Option D is correct because the SpeechSynthesizer method executes speech to text and output to the speaker.

You may also output to a file or as an in memory stream using the SpeechSynthesizer method.

Reference:

To learn more about text to speech output, use the link given below:

Sure, I can provide a detailed explanation of the code and the answer choices for you.

The code you provided is a C# method that uses the Azure Speech service to synthesize speech and output it to a speaker. The method is named SynthesizeAudioAsync and it is an asynchronous method, which means that it will run in the background and not block the main thread of the application.

The code contains some placeholders denoted by <subscription key>, <azure region> and <speaker output> that need to be replaced with actual values.

To use Azure Speech service in the code, you need to create a SpeechConfig object that contains the subscription key and the Azure region. The subscription key is a unique identifier that links your application to your Azure Speech service account, and the Azure region is the geographical region where your Speech service instance is hosted.

The answer choices A and D are both related to SpeechConfig and SpeechSynthesizer objects, which are the correct choices to fill in the missing code in the method. Specifically:

  • Answer choice A (SpeechConfig) is the correct choice to instantiate a new SpeechConfig object and set it up with the subscription key and Azure region. You can use the static FromSubscription method of the SpeechConfig class to create a new SpeechConfig object and pass the subscription key and Azure region as arguments. The completed code for this part would look like this:

var config = SpeechConfig.FromSubscription("<subscription key>", "<azure region>");

  • Answer choice D (SpeechSynthesizer) is the correct choice to instantiate a new SpeechSynthesizer object and use it to synthesize speech from a text input. The SpeechSynthesizer class provides methods to synthesize speech from various input sources such as text, SSML (Speech Synthesis Markup Language) and audio data streams. You can create a new SpeechSynthesizer object by passing the SpeechConfig object created earlier as an argument to its constructor. The completed code for this part would look like this:

using var synthesizer = new SpeechSynthesizer(config);

Therefore, the correct answer is A and D, SpeechConfig and SpeechSynthesizer. Answer choices B and C are not applicable to the code as they are related to AudioConfig and AudioDataStream objects, which are not used in this specific scenario of synthesizing speech and outputting it to a speaker.