Skip to main content

XSpeechSynthesizerCreate

Creates a speech synthesizer.

Syntax

Parameters

speechSynthesizer   _Out_
Type: XSpeechSynthesizerHandle*
The handle to the created speech synthesizer.

Return value

Type: HRESULT Returns S_OK if successful; otherwise, returns an error code. For a list of error codes, see Error Codes.

Remarks

This function isn’t safe to call on a time-sensitive thread. For more information, see Time-sensitive threads.
Use this function to create and receive the handle to a new speech synthesizer instance, which provides access to the functionality of an installed speech synthesis engine, or voice. By default, a new speech synthesizer instance uses the current system voice. To enumerate and get information about the voices installed on the current device, use the XSpeechSynthesizerEnumerateInstalledVoices function along with the XSpeechSynthesizerInstalledVoicesCallback callback function. For each installed voice, the XSpeechSynthesizerVoiceInformation structure provides the voice ID, description, display text, gender, language, and other information. Invoke XSpeechSynthesizerSetCustomVoice to use a different installed voice, or invoke XSpeechSynthesizerSetDefaultVoice to use the current system voice again. After creating a speech synthesizer handle and specifying a voice, use the XSpeechSynthesizerCreateStreamFromText function to create a speech synthesizer stream and to synthesize speech from plain text. Use the XSpeechSynthesizerGetStreamDataSize and XSpeechSynthesizerGetStreamData functions to get the audio data for the synthesized speech from the speech synthesizer stream, then use the XSpeechSynthesizerCloseStreamHandle function to close the speech synthesizer stream after all outstanding asynchronous operations are completed. Use the XSpeechSynthesizerCloseHandle function to close the speech synthesizer and to release system resources after you’re done using the speech synthesizer. To prevent memory leaks, call the XSpeechSynthesizerCloseHandle function to close a speech synthesizer handle after you’ve completed all operations that are using the handle. The following example demonstrates how to synthesize speech from plain text by using a speech synthesizer and an installed voice, and how to synthesize audio data with a speech synthesizer stream. The XSpeechSynthesizerCreate and XSpeechSynthesizerSetCustomVoice functions create a speech synthesizer instance and, optionally, assign a custom voice to it if a voice ID is specified in voiceId. Then, the XSpeechSynthesizerCreateStreamFromText function creates a speech synthesizer stream and synthesizes speech from the plain text specified in textToSpeak. After the stream is created, the XSpeechSynthesizerGetStreamDataSize and XSpeechSynthesizerGetStreamData functions retrieve the audio data for the synthesized speech to be played from the stream. Finally, after the playing of audio data is completed, the XSpeechSynthesizerCloseStreamHandle and XSpeechSynthesizerCloseHandle functions close the speech synthesizer stream and speech synthesizer.

Requirements

Header: XSpeechSynthesizer.h Library: xgameruntime.lib Supported platforms: Windows, XBOX One family consoles and XBOX Series consoles

Conceptual documentation

See also

XAccessibility
XSpeechSynthesizerCloseHandle
XSpeechSynthesizer
Last modified on August 20, 2026