> ## 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

从指定的纯文本创建语音合成流。

## 语法

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

### 参数

*speechSynthesizer*   \_In\_\
类型：XSpeechSynthesizerHandle

要使用的语音合成器。

*text*   \_In\_z\_\
类型：char\*

要生成语音的纯文本。

*speechSynthesisStream*   \_Out\_\
类型：XSpeechSynthesizerStreamHandle\*

表示从 *text* 中指定的纯文本生成的语音的语音合成流。

### 返回值

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

如果成功，则返回 **S\_OK**；否则返回错误代码。有关错误代码列表，请参阅[错误代码](/reference/errorcodes)。如果因为语音合成器流大于最大数据大小而函数失败，则返回值将设为 **E\_BOUNDS**。

## 备注

<Note>此函数在时间敏感型线程上调用不安全。有关详细信息，请参阅[时间敏感型线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

* 使用此函数可从纯文本合成语音并生成 WAVE 容器（`audio/wav` MIME 类型）格式的音频数据。使用此函数创建语音合成器流并从纯文本合成语音后，使用 [XSpeechSynthesizerGetStreamDataSize](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizergetstreamdatasize) 和 [XSpeechSynthesizerGetStreamData](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizergetstreamdata) 函数从语音合成器流中检索音频数据。在检索完音频数据后，使用 [XSpeechSynthesizerCloseStreamHandle](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerclosestreamhandle) 函数关闭语音合成器流。

* 语音合成器流的最大数据大小为 0xffffffff 字节：四千兆字节减一字节。如果尝试创建大于最大数据大小的语音合成器流，则会发生错误。

* 为防止内存泄漏，在完成使用该句柄的所有操作后，请调用 [XSpeechSynthesizerCloseStreamHandle](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerclosestreamhandle) 函数关闭语音合成器流句柄。在调用此函数之前，必须完成所有未完成的异步操作。

* 有关演示如何使用 **XSpeechSynthesizerCreateStreamFromText** 函数的示例，请参阅 [XSpeechSynthesizerCreate](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreate)。

## 要求

**头文件：** XSpeechSynthesizer.h

**库：** xgameruntime.lib

**支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

## 概念文档

* [文本转语音](/build/console-features/text-to-speech/text-to-speech)
* [时间敏感型线程](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 另请参阅

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