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

# XSpeechSynthesizerSetCustomVoice

> XSpeechSynthesizerSetCustomVoice

# XSpeechSynthesizerSetCustomVoice

指定语音合成器将使用指定的自定义语音。

## 语法

```cpp theme={null}
HRESULT XSpeechSynthesizerSetCustomVoice(  
         XSpeechSynthesizerHandle speechSynthesizer,  
         const char* voiceId  
)  
```

### 参数

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

指定将使用自定义语音的语音合成器。

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

一个 [XSpeechSynthesizerVoiceInformation](/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation) 结构中的语音 ID，在 [XSpeechSynthesizerInstalledVoicesCallback](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback) 函数中返回。

### 返回值

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

如果成功，则返回 **S\_OK**；否则返回错误代码。有关错误代码列表，请参阅[错误代码](/reference/errorcodes)。

## 备注

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

* 对于每个已安装的语音，[XSpeechSynthesizerVoiceInformation](/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation) 结构提供语音 ID、说明、显示文本、性别、语言和其他信息。

* 若要枚举并获取当前设备上已安装语音的信息，请使用 [XSpeechSynthesizerEnumerateInstalledVoices](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerenumerateinstalledvoices) 函数以及 [XSpeechSynthesizerInstalledVoicesCallback](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback) 回调函数。

* 若要为指定的语音合成器使用当前系统语音，请调用 [XSpeechSynthesizerSetDefaultVoice](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizersetdefaultvoice)。

* 有关演示如何使用 **XSpeechSynthesizerSetCustomVoice** 函数的示例，请参阅 [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)\
[XSpeechSynthesizerCreateStreamFromText](/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreatestreamfromtext)\
[XSpeechSynthesizer](/reference/system/xspeechsynthesizer/xspeechsynthesizer_members)


## Related topics

- [XSpeechSynthesizerEnumerateInstalledVoices](/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerenumerateinstalledvoices.md)
- [XSpeechSynthesizerInstalledVoicesCallback](/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback.md)
- [XSpeechSynthesizerVoiceInformation](/zh-CN/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation.md)
- [XSpeechSynthesizerSetDefaultVoice](/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizersetdefaultvoice.md)
- [XSpeechSynthesizer](/zh-CN/reference/system/xspeechsynthesizer/xspeechsynthesizer_members.md)
