Skip to content

Commit f9a7435

Browse files
authored
Merge pull request #185202 from eric-urban/patch-1
Update text-to-speech-basics-python.md
2 parents 9e71377 + bea5090 commit f9a7435

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

articles/cognitive-services/Speech-Service/includes/how-to/text-to-speech-basics/text-to-speech-basics-python.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: eric-urban
33
ms.service: cognitive-services
44
ms.topic: include
5-
ms.date: 07/02/2021
5+
ms.date: 01/16/2022
66
ms.author: eur
77
---
88

@@ -43,7 +43,7 @@ There are a few ways that you can initialize a [`SpeechConfig`](/python/api/azur
4343
In this example, you create a [`SpeechConfig`](/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.speechconfig) using a speech key and location/region. Get these credentials by following steps in [Try the Speech service for free](../../../overview.md#try-the-speech-service-for-free).
4444

4545
```python
46-
speech_config = SpeechConfig(subscription="<paste-your-speech-key-here>", region="<paste-your-speech-location/region-here>")
46+
speech_config = speechsdk.SpeechConfig(subscription="<paste-your-speech-key-here>", region="<paste-your-speech-location/region-here>")
4747
```
4848

4949
## Select synthesis language and voice
@@ -67,13 +67,13 @@ Next, you create a [`SpeechSynthesizer`](/python/api/azure-cognitiveservices-spe
6767
To start, create an `AudioOutputConfig` to automatically write the output to a `.wav` file, using the `filename` constructor param.
6868

6969
```python
70-
audio_config = AudioOutputConfig(filename="path/to/write/file.wav")
70+
audio_config = speechsdk.audio.AudioOutputConfig(filename="path/to/write/file.wav")
7171
```
7272

7373
Next, instantiate a `SpeechSynthesizer` by passing your `speech_config` object and the `audio_config` object as params. Then, executing speech synthesis and writing to a file is as simple as running `speak_text_async()` with a string of text.
7474

7575
```python
76-
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
76+
synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
7777
synthesizer.speak_text_async("A simple test to write to a file.")
7878
```
7979

@@ -84,7 +84,7 @@ Run the program, and a synthesized `.wav` file is written to the location you sp
8484
In some cases, you may want to directly output synthesized speech directly to a speaker. To do this, use the example in the previous section, but change the `AudioOutputConfig` by removing the `filename` param, and set `use_default_speaker=True`. This outputs to the current active output device.
8585

8686
```python
87-
audio_config = AudioOutputConfig(use_default_speaker=True)
87+
audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)
8888
```
8989

9090
## Get result as an in-memory stream
@@ -103,7 +103,7 @@ It's simple to make this change from the previous example. First, remove the `Au
103103
This time, you save the result to a [`SpeechSynthesisResult`](/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.speechsynthesisresult) variable. The `audio_data` property contains a `bytes` object of the output data. You can work with this object manually, or you can use the [`AudioDataStream`](/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.audiodatastream) class to manage the in-memory stream. In this example you use the `AudioDataStream` constructor to get a stream from the result.
104104

105105
```python
106-
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=None)
106+
synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=None)
107107
result = synthesizer.speak_text_async("Getting the response as an in-memory stream.").get()
108108
stream = AudioDataStream(result)
109109
```
@@ -127,10 +127,10 @@ In this example, you specify a high-fidelity RIFF format `Riff24Khz16BitMonoPcm`
127127

128128
```python
129129
speech_config.set_speech_synthesis_output_format(SpeechSynthesisOutputFormat["Riff24Khz16BitMonoPcm"])
130-
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=None)
130+
synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=None)
131131

132132
result = synthesizer.speak_text_async("Customizing audio output format.").get()
133-
stream = AudioDataStream(result)
133+
stream = speechsdk.AudioDataStream(result)
134134
stream.save_to_wav_file("path/to/write/file.wav")
135135
```
136136

@@ -158,17 +158,17 @@ Next, you need to change the speech synthesis request to reference your XML file
158158
> `encoding` parameter as follows: `open("ssml.xml", "r", encoding="utf-8-sig")`.
159159
160160
```python
161-
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=None)
161+
synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=None)
162162

163163
ssml_string = open("ssml.xml", "r").read()
164164
result = synthesizer.speak_ssml_async(ssml_string).get()
165165

166-
stream = AudioDataStream(result)
166+
stream = speechsdk.AudioDataStream(result)
167167
stream.save_to_wav_file("path/to/write/file.wav")
168168
```
169169

170170
> [!NOTE]
171-
> To change the voice without using SSML, you can set the property on the `SpeechConfig` by using `SpeechConfig.speech_synthesis_voice_name = "en-US-JennyNeural"`
171+
> To change the voice without using SSML, you can set the property on the `SpeechConfig` by using `speech_config.speech_synthesis_voice_name = "en-US-JennyNeural"`
172172
173173
## Get facial pose events
174174

0 commit comments

Comments
 (0)