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

# XSpeechSynthesizerCreateStreamFromSsml

> XSpeechSynthesizerCreateStreamFromSsml

# XSpeechSynthesizerCreateStreamFromSsml

从指定的 SSML 创建语音合成流。

## 语法

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

### 参数

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

要使用的语音合成器。

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

要朗读的 SSML 修饰文本。有关 SSML 标记的详细信息，请参阅 [W3C 建议](https://go.microsoft.com/fwlink/p/?LinkID=201763)。

<Note>此 API 要求调用方使用 SSML 1.0 版。</Note>

*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) 函数关闭语音合成器流句柄。在调用此函数之前，必须完成所有未完成的异步操作。

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

## 要求

**头文件：** XSpeechSynthesizer.h

**库：** xgameruntime.lib

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

## 另请参阅

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


## Related topics

- [XSpeechSynthesizer](/zh-CN/reference/system/xspeechsynthesizer/xspeechsynthesizer_members.md)
- [面向 GDK 的 Unity C# API 包装器](/zh-CN/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XSpeechSynthesizerCreateStreamFromText](/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreatestreamfromtext.md)
- [XSpeechSynthesizerCreate](/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreate.md)
- [文本转语音](/zh-CN/build/console-features/text-to-speech/text-to-speech.md)
