node.js - 如何在网络聊天中使用新的 Azure 语音服务而不是 Bing 语音
问题描述
我有一个网络聊天机器人工作正常(我可以使用语音并返回语音)使用以下链接的必应语音:
使用选项 3:
const speechOptions = {
speechRecognizer: new CognitiveServices.SpeechRecognizer({ subscriptionKey: 'YOUR_COGNITIVE_SPEECH_API_KEY' }),
speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
gender: CognitiveServices.SynthesisGender.Female,
subscriptionKey: 'YOUR_COGNITIVE_SPEECH_API_KEY',
voiceName: 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)'
})
};
但是,我正在尝试从 Bing Speech API 切换到 Speech Services AP,因为 Bing Speech 即将退役。
有谁知道如何为我的网络聊天机器人执行此操作?
解决方案
webchat v3 不支持 azure 的 Cognitive Speech Service。但在 webchat v4 中,您可以通过以下代码进行集成
const config = {
method: "POST",
headers: {
Authorization:
"Bearer xxwebchatsecretkeyxx"
}
};
const res = await fetch(
"https://directline.botframework.com/v3/directline/tokens/generate",
config
);
const subscriptionKey = "speech service subscription key";
const { token } = await res.json();
let directLine = window.WebChat.createDirectLine({ token });
window.WebChat.renderWebChat(
{
directLine,
webSpeechPonyfillFactory: await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory(
{
region: "westus",
subscriptionKey
}
),
userID: model.id,
styleSet,
store
},
document.getElementById("webchat")
);
推荐阅读
- oracle - 使用动态更新查询更新 Ledger_stat 表中的天数列的值
- c# - 未在多线程程序中读取正确的属性值
- ajax - parsererror SyntaxError: 位置 0 的 JSON 中的意外标记 <
- java - 从泛型类型参数中检索高级信息
- xml - 为 Coldfusion 应用程序的 SSO 计算 XML 元数据中的 DigestValue 和 SignatureValue
- regex - 正则表达式搜索 von Bibtex 文件以提取捕获组中的引用键和标题
- javascript - 有一个按钮来控制时间线 GSAP 动态定位增量计数器
- python - Selenium 找不到链接的元素
- docker - 当 env 中未设置变量时,docker-compose 在随机端口上公开
- java - Bouncy Castle - 如何从 JceOpenSSLPKCS8DecryptorProviderBuilder 获取公钥信息