我正在尝试在Microsoft Webchat中启用“文本到语音”选项,并使用了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
}
};
};
答案 0 :(得分:0)
您可以通过selectVoice
方法来支持Web聊天,以选择要使用的语音。请查看下面的代码片段和Select Voice网络聊天示例,以了解更多详细信息。另外,这是voices Web聊天支持的列表。
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')
);
希望这会有所帮助!