> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XSpeechSynthesizerCreateStreamFromText

> XSpeechSynthesizerCreateStreamFromText

# XSpeechSynthesizerCreateStreamFromText

Creates a speech synthesis stream from the specified plain text.

## Syntax

```cpp theme={null}
HRESULT XSpeechSynthesizerCreateStreamFromText(  
         XSpeechSynthesizerHandle speechSynthesizer,  
         const char* text,  
         XSpeechSynthesizerStreamHandle* speechSynthesisStream  
)  
```

### Parameters

*speechSynthesizer*   \_In\_\
Type: XSpeechSynthesizerHandle

The speech synthesizer to use.

*text*   \_In\_z\_\
Type: char\*

The plain text from which to generate speech.

*speechSynthesisStream*   \_Out\_\
Type: XSpeechSynthesizerStreamHandle\*

A speech synthesis stream that represents the speech generated from the plain text specified in *text*.

### Return value

Type: [HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

Returns **S\_OK** if successful; otherwise, returns an error code. For a list of error codes, see [Error Codes](/reference/errorcodes). If the function fails because the speech synthesizer stream is larger than the maximum data size, the return value is set to **E\_BOUNDS**.

## Remarks

<Note>This function isn't safe to call on a time-sensitive thread. For more information, see [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads).</Note>

* Use this function to synthesize speech from plain text and to generate audio data in the WAVE container (`audio/wav` MIME type) format. After using this function to create a speech synthesizer stream and to synthesize speech from plain text, use the [XSpeechSynthesizerGetStreamDataSize](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizergetstreamdatasize) and [XSpeechSynthesizerGetStreamData](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizergetstreamdata) functions to retrieve the audio data from the speech synthesizer stream. Use the [XSpeechSynthesizerCloseStreamHandle](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerclosestreamhandle) function to close the speech synthesizer stream after you've retrieved the audio data.

* The maximum data size of a speech synthesizer stream is 0xffffffff bytes: four gigabytes minus one byte. An error occurs if you attempt to create a speech synthesizer stream larger than the maximum data size.

* To prevent memory leaks, call the [XSpeechSynthesizerCloseStreamHandle](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerclosestreamhandle) function to close a speech synthesizer stream handle after you've completed all operations that are using the handle. All outstanding asynchronous operations must be completed before this function is called.

* For an example that demonstrates how to use the **XSpeechSynthesizerCreateStreamFromText** function, see [XSpeechSynthesizerCreate](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreate).

## Requirements

**Header:** XSpeechSynthesizer.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## Conceptual documentation

* [Text-to-speech](/build/console-features/text-to-speech/text-to-speech)
* [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[XAccessibility](/reference/system/xaccessibility/xaccessibility_members)\
[XSpeechSynthesizerCloseStreamHandle](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerclosestreamhandle)\
[XSpeechSynthesizer](/reference/system/xspeechsynthesizer/xspeechsynthesizer_members)


## Related topics

- [Text-to-speech](/build/console-features/text-to-speech/text-to-speech.md)
- [XSpeechSynthesizerCreate](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreate.md)
- [XSpeechSynthesizer](/reference/system/xspeechsynthesizer/xspeechsynthesizer_members.md)
- [XSpeechSynthesizerGetStreamDataSize](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizergetstreamdatasize.md)
- [XSpeechSynthesizerVoiceInformation](/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation.md)
