我正在尝试将MS botframework示例(https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/06.c.cognitive-services-speech-services-js)中的Mock-Bot转换为使用我自己的Cognitive Services资源。我尝试更改端点中的区域,但无济于事。对于下面的代码,我得到此错误:GET https://westus.tts.speech.microsoft.com/cognitiveservices/voices/list net :: ERR_ABORTED 401。
final Map<String, dynamic> tempMap = json.decode(jsonValue);
tempMap.removeWhere((String key, dynamic value)=>!includeNull&&value==null);
请帮助。
编辑:显然,错误是SyntaxError:JSON位置0处的意外令牌e。
答案 0 :(得分:0)
我不确定为什么上面会产生错误,但是如果我简化一下,错误就会消失。试试这个对我有用的东西:
let authorizationToken;
let region;
const speechServicesTokenRes = await fetch(
'https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken',
{ method: 'POST', headers: { 'Ocp-Apim-Subscription-Key': 'MyCognitiveServicesSubscriptionKey' } }
);
if (speechServicesTokenRes.status === 200) {
region = 'westeurope',
authorizationToken = await speechServicesTokenRes.text()
} else {
return (new Error('error!'))
}
const webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory( {
authorizationToken: authorizationToken,
region: region
} );
window.WebChat.renderWebChat({
directLine: directLine,
webSpeechPonyfillFactory: webSpeechPonyfillFactory
}, document.getElementById('webchat') );
希望有帮助!