本节包含针对特定游戏引擎集成场景的补充说明。
除了 speechEngine 插件库,在 Windows 上运行时还需要语音动态库(如 vt_eng.dll 英语库或 vt_fre.dll 法语库)。
要在构建阶段复制所需的库,请使用 Unity Editor 辅助脚本。该脚本位于 Unity 工程的以下目录中:SDK/Plugins/speechEngine/Unity/Editor/SpeechEnginePluginImporterScript.cs。
所有运行时发送的文本都必须采用 UTF-8 字符编码。对于有些平台,可能要将文本由别的编码类型转换为 UTF-8。以下针对 Unity 和 Unreal 的示例代码展示了如何将 Windows 上默认的 UTF-16 编码转换为 UTF-8。对于其他平台,可能要根据所用的编码类型对代码进行修改。
Unity:
public byte[] ConvertUtf16ToUtf8Bytes(string utf16String)
{
// 获取 UTF-8 编码
Encoding utf8 = Encoding.UTF8;
// 将 UTF-16 字符串转换为 UTF-8 字节数组
byte[] utf8Bytes = utf8.GetBytes(utf16String);
return utf8Bytes;
}
byte[] textArray = ConvertUtf16ToUtf8Bytes(Text);
System.Runtime.InteropServices.GCHandle pinned = System.Runtime.InteropServices.GCHandle.Alloc(textArray, System.Runtime.InteropServices.GCHandleType.Pinned);
IntPtr address = pinned.AddrOfPinnedObject();
AkUnitySoundEngine.SendPluginCustomGameData(0, this.gameObject, AkPluginType.AkPluginTypeSource, 312, 1, address, (uint)textArray.Length + 1);
pinned.Free();
Unreal:
FString utf16_text = TEXT("This is a UTF-16 string at its core.");
FStringView fStringView(utf16_text);
auto ConvertedTemp = StringCast(fStringView.GetData(), fStringView.Len());
auto utf8_text = ConvertedTemp.Get();
SoundEngine->SendPluginCustomGameData(0, 100, AkPluginTypeSource, 312, 1, utf8_text, ConvertedTemp.Length() + 1);
speechEngine 插件不支持 Mac 平台。但若通过 Wwise Unreal/Unity Integration 来生成 SoundBank,将自动为 Mac 生成 SoundBank,而这可能会导致发生错误。因此,建议针对 Mac 以显式方式从工程中弃用所有 speechEngine 元素以避免此类错误。有关详细信息,请参阅从平台中弃用工程元素。
要编译 IntegrationDemo 的 speechEngine 插件页面,您需要修改随 Wwise SDK 一并提供的 Xcode 工程。
在 IntegrationDemo Xcode 属性中:
在 General - Frameworks, Libraries and Embedded Content 下:
添加 Applications/Audiokinetic/Wwise[version]/SDK/iOS_Xcode[version]/[configuration]/bin 下找到的所有 vt_[lang]_q22.framework 文件。
在 Build Settings 下:
将 @executable_path/Frameworks 添加到 Runpath Search Paths。
将 ../../../iOS_Xcode$(XCODE_VERSION_MAJOR)/Profile$(EFFECTIVE_PLATFORM_NAME)/bin 添加到 Framework Search Paths。