> ## 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-TW/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation.md) 結構中的語音識別碼，由 [XSpeechSynthesizerInstalledVoicesCallback](https://docs.xbox.com/zh-TW/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-TW/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-TW/reference/system/xspeechsynthesizer/structs/xspeechsynthesizervoiceinformation.md) 結構會提供語音識別碼、描述、顯示文字、性別、語言及其他資訊。

* 若要列舉並取得目前裝置上所安裝之語音的相關資訊，請搭配使用 [XSpeechSynthesizerEnumerateInstalledVoices](https://docs.xbox.com/zh-TW/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerenumerateinstalledvoices.md) 函式與 [XSpeechSynthesizerInstalledVoicesCallback](https://docs.xbox.com/zh-TW/reference/system/xspeechsynthesizer/functions/xspeechsynthesizerinstalledvoicescallback.md) 回呼函式。

* 若要讓指定的語音合成器使用目前的系統語音，請呼叫 [XSpeechSynthesizerSetDefaultVoice](https://docs.xbox.com/zh-TW/reference/system/xspeechsynthesizer/functions/xspeechsynthesizersetdefaultvoice.md)。

* 如需示範如何使用 **XSpeechSynthesizerSetCustomVoice** 函式的範例，請參閱 [XSpeechSynthesizerCreate](https://docs.xbox.com/zh-TW/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreate.md)。

## 需求

**標頭：** XSpeechSynthesizer.h

**程式庫：** xgameruntime.lib

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 概念文件

* [文字轉換語音](https://docs.xbox.com/zh-TW/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-TW/reference/system/xaccessibility/xaccessibility_members.md)\
[XSpeechSynthesizerCreateStreamFromText](https://docs.xbox.com/zh-TW/reference/system/xspeechsynthesizer/functions/xspeechsynthesizercreatestreamfromtext.md)\
[XSpeechSynthesizer](https://docs.xbox.com/zh-TW/reference/system/xspeechsynthesizer/xspeechsynthesizer_members.md)


## Related topics

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