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

# 使用 Cognitive Services

> 了解如何透過 OSS 外掛程式，在 Unreal Engine 專案中使用 PlayFab Party Cognitive Services 進行語音轉文字、文字轉語音和翻譯。

# Cognitive Services 簡介

PlayFab Party Cognitive Services 介面包含可設定及使用 PlayFab Party 所提供之協助工具功能的函式。

這些功能包括：

* 即時文字聊天翻譯
* 即時語音聊天轉譯
* 即時語音聊天轉譯翻譯
* 文字轉語音合成

## 定價

核心 VOIP 和遊戲網路功能以外的 Cognitive Services 和其他服務可能會有相關費用。如需詳細資料，請造訪 [PlayFab Party 的計費](/zh-TW/services/playfab/pricing/meters/meters#party)頁面，或連絡您的 Microsoft 代表。

## 使用 Cognitive Services 介面

若要在遊戲中使用 Cognitive Services 介面，請將下列程式碼區塊新增至遊戲的 Build.cs 檔案。

```csharp theme={null}
if (Target.bGenerateProjectFiles || (Target.Type != TargetType.Game && Target.Type != TargetType.Client))
{
	PublicDefinitions.Add("WITH_OSS_PLAYFAB_COGNITIVESERVICES=0");
}
else
{
	PublicDefinitions.Add("WITH_OSS_PLAYFAB_COGNITIVESERVICES=1");

	PublicDependencyModuleNames.Add("OnlineSubsystemPlayFab");
	PrivateDependencyModuleNames.Add("HTTP");
}
```

此外，您可以使用 **#if WITH\_OSS\_PLAYFAB\_COGNITIVESERVICES** 包裝任何遊戲程式碼，以防止在不使用 Cognitive Services 的平台上發生編譯錯誤。

## SetTextChatTranslationOptions

SetTextChatTranslationOptions 可開啟或關閉聊天翻譯。

## SetVoiceChatTranscriptionOptions

啟用及設定語音轉譯時需要 SetVoiceChatTranscriptionOptions。

* **bTranscribeSelf** - 會產生本機聊天控制項的轉譯，並提供給同一個本機聊天控制項
* **bTranscribeOtherChatControlsWithMatchingLanguages** - 會產生與本機聊天控制項語言相同之其他聊天控制項的轉譯，並提供給本機聊天控制項
* **bTranscribeOtherChatControlsWithNonMatchingLanguages** - 會產生語言與本機聊天控制項語言不同之其他聊天控制項的轉譯，並提供給本機聊天控制項
* **bTranslateToLocalLanguage** - 轉譯會翻譯為本機聊天控制項的語言

## SetTextToSpeechOptions

啟用及設定文字轉語音時需要 SetTextToSpeechOptions。

* **ETextToSpeechType::Narration** - 將音訊轉譯至本機聊天控制項的音訊輸出
* **ETextToSpeechType::VoiceChat** - 將音訊轉譯至本機聊天控制項設定為傳送音訊的聊天控制項

## SendTextAsVoice

產生文字轉語音的音訊，並傳送至連線到 PlayFab Party 網路的所有其他用戶端。
呼叫 **SendTextAsVoice** 之前，必須先呼叫 **SetTextToSpeechOptions** 啟用文字轉語音

## SendChatText

將聊天文字字串傳送至連線到 PlayFab Party 網路的所有其他用戶端。


## Related topics

- [使用 Google Play Games Services 登入](/zh-TW/services/playfab/api-references/rest/client/authentication/login-with-google-play-games-services.md)
- [來賓使用者概觀](/zh-TW/build/core-features/common/user/users-guest-overview.md)
- [PlayFab Party Unity 外掛程式版本資訊](/zh-TW/services/playfab/multiplayer/networking/party-unity-release-notes.md)
- [PlayFab Party QoS 測量](/zh-TW/services/playfab/multiplayer/networking/concepts-regions.md)
- [PlayFab Party 連接埠使用方式與防火牆需求](/zh-TW/services/playfab/multiplayer/networking/concepts-port-usage.md)
