Skip to content

Commit d7b451f

Browse files
Update how-to-lower-speech-synthesis-latency.md
1 parent c8c8078 commit d7b451f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

articles/ai-services/speech-service/how-to-lower-speech-synthesis-latency.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,28 @@ For detailed implementation, see the [sample code on GitHub](https://github.com/
360360

361361
::: zone pivot="programming-language-python"
362362

363+
See the sample code for setting the endpoint:
364+
365+
```python
366+
# IMPORTANT: MUST use the websocket v2 endpoint
367+
speech_config = speechsdk.SpeechConfig(endpoint=f"wss://{os.getenv('AZURE_TTS_REGION')}.tts.speech.microsoft.com/cognitiveservices/websocket/v2",
368+
subscription=os.getenv("AZURE_TTS_API_KEY"))
369+
```
370+
371+
#### Key steps
372+
373+
1. **Create a text stream request**: Use `speechsdk.SpeechSynthesisRequestInputType.TextStream` to initiate a text stream.
374+
1. **Set global properties**: Adjust settings such as output format and voice name directly, as the feature handles partial text inputs and doesn't support SSML. Refer to the following sample code for instructions on how to set them. OpenAI text to speech voices aren't supported by the text streaming feature. See this [language table](language-support.md?tabs=tts#supported-languages) for full language support.
375+
376+
```python
377+
# set a voice name
378+
speech_config.speech_synthesis_voice_name = "en-US-AvaMultilingualNeural"
379+
```
380+
381+
1. **Stream your text**: For each text chunk generated from a GPT model, use `request.input_stream.write(text)` to send the text to the stream.
382+
1. **Close the stream**: Once the GPT model completes its output, close the stream using `request.input_stream.close()`.
363383

384+
For detailed implementation, see the [sample code on GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/samples/python/tts-text-stream).
364385
365386
::: zone-end
366387

0 commit comments

Comments
 (0)