> ## Documentation Index
> Fetch the complete documentation index at: https://docs.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](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation.md) 结构中的语音 ID，在 [XSpeechSynthesizerInstalledVoicesCallback](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback.md) 函数中返回。

### 返回值

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

如果成功，则返回 **S\_OK**；否则返回错误代码。有关错误代码列表，请参阅[错误代码](https://docs.xbox.com/zh-CN/reference/errorcodes.md)。

## 备注

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

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

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

* 若要为指定的语音合成器使用当前系统语音，请调用 [XSpeechSynthesizerSetDefaultVoice](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizersetdefaultvoice.md)。

* 有关演示如何使用 **XSpeechSynthesizerSetCustomVoice** 函数的示例，请参阅 [XSpeechSynthesizerCreate](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreate.md)。

## 要求

**头文件：** XSpeechSynthesizer.h

**库：** xgameruntime.lib

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

## 概念文档

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

## 另请参阅

[XAccessibility](https://docs.xbox.com/zh-CN/reference/system/xaccessibility/xaccessibility_members.md)\
[XSpeechSynthesizerCreateStreamFromText](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreatestreamfromtext.md)\
[XSpeechSynthesizer](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/xspeechsynthesizer_members.md)


## Related topics

- [XSpeechSynthesizerInstalledVoicesCallback](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback.md)
- [XSpeechSynthesizerEnumerateInstalledVoices](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerenumerateinstalledvoices.md)
- [XSpeechSynthesizerVoiceInformation](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation.md)
- [XSpeechSynthesizerSetDefaultVoice](https://docs.xbox.com/zh-CN/reference/system/xspeechsynthesizer/functions/xspeechsynthesizersetdefaultvoice.md)
- [文本转语音](https://docs.xbox.com/zh-CN/build/console-features/text-to-speech/text-to-speech.md)
