botframework - 使用 BrowserWebSpeech 在网络聊天中更改语音
问题描述
我正在尝试在 Microsoft Webchat 中启用 Text to Speech 选项并使用 createBrowserWebSpeechPonyfillFactory 选项。
如何更改此选项的声音?我想为“en-US”使用女性声音,但它总是使用男性声音播放。
尝试了下面的代码,但没有帮助
async function speechServicesPonyfillFactory() {
const speechServicesPonyfillFactory = await window.WebChat.createBrowserWebSpeechPonyfillFactory();
return options => {
const ponyfill = speechServicesPonyfillFactory(options);
var speechSynthesisUtterance = ponyfill.SpeechSynthesisUtterance;
var speechSynthesis = ponyfill.speechSynthesis;
var voices = speechSynthesis.getVoices();
speechSynthesisUtterance.voice = voices.filter(function(voice) { return voice.name == 'Microsoft Zira Desktop - English (United States)'; })[0];
return {
SpeechGrammarList: ponyfill.SpeechGrammarList,
SpeechRecognition: ponyfill.SpeechRecognition,
speechSynthesis: speechSynthesis,
SpeechSynthesisUtterance: speechSynthesisUtterance
}
};
};
解决方案
您可以将selectVoice
方法作为道具传递给 Web Chat 以选择要使用的语音。查看下面的代码片段和选择语音网络聊天示例以了解更多详细信息。此外,这里是网络聊天支持的语音列表。
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({ token }),
selectVoice: (voices, activity) =>
// If the activity is in zh-HK, use a voice with keyword "TracyRUS" (Cantonese).
// Otherwise, use "JessaNeural" (preferred) or "Jessa".
activity.locale === 'zh-HK'
? voices.find(({ name }) => /TracyRUS/iu.test(name))
: voices.find(({ name }) => /JessaNeural/iu.test(name)) ||
voices.find(({ name }) => /Jessa/iu.test(name)),
webSpeechPonyfillFactory
},
document.getElementById('webchat')
);
希望这可以帮助!
推荐阅读
- c++ - 如何使用 C++、CMake 和 Tensorflow 修复“ld: symbol(s) not found for architecture x86_64”?
- visual-studio - 作为构建的一部分,如何将文件复制和重命名到输出文件夹
- python - Python Flask 应用程序路由运行不正常
- vue.js - VuePress/Vue:使用 GitLab CI 构建期间未使用的插件
- python - Python面板按钮回调函数
- php - exec("mysqldump") 返回 2 但该命令在命令行中工作
- javascript - Webrtc 媒体流正在工作,但数据通道关闭(根本不启动)
- python - “正面”出现的概率是多少?
- python - 有没有办法从 Python 使用 IBM 查询加速器?
- php - 如何设置每行 4 个项目?(PHP/HTML/CSS) 非表