你好,所以默认语言是英语,我想改成德语。我目前使用的是选项3,但还是不行。有什么问题吗?
<script
> src="https://cdn.botframework.com/botframework-webchat/latest/CognitiveServices.js"></script>
> <script>
> const params = BotChat.queryParams(location.search);
> const user = {
> id: params['userid'] || 'userid',
> name: params['username'] || 'username'
> };
>
> const bot = {
> id: params['botid'] || 'botid',
> name: params['botname'] || 'botname'
> };
>
> window.botchatDebug = params['debug'] && params['debug'] === 'true';
>
> const speechOptions =
>
> speechRecognizer: new CognitiveServices.SpeechRecognizer({ SpeechRecognitionLanguage: 'de-de', subscriptionKey: 'xxxxx' }),
> speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
> locale: 'de-de',
> gender: CognitiveServices.SynthesisGender.Female,
> subscriptionKey: 'xxxxxxx',
> voiceName: 'Microsoft Server Speech Text to Speech Voice (de-DE, KatjaNeural)'
> })
> };
> BotChat.App({
> bot: bot,
> locale: params['de-DE'],
> resize: 'detect',
>
> speechOptions: speechOptions,
> user: user,
>
> directLine: {
> domain: params['domain'],
> secret: params['s'],
> token: params['t'],
> webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
> }
> }, document.getElementById('BotChatGoesHere')); </script> </body> </html>
有什么想法或代码可以解决我的问题吗?
不工作的原因是 "params "中没有相关的值可以读取。根据上面的代码,"params "设置为 location.search
在我的例子中,其内容为 {"": "undefined"}
因为 location.search
决心 ""
本身。此外,你把 "de-DE "当作一个传入的值,而实际上你提供的是一个键(不存在),然后返回一个值(不存在)。
如果你真的想使用 "params",那就给它分配一个键值对,就像这样。params['locale'] = 'de-DE'
.
如果你想放弃使用 "params",那么就直接分配locale,就像这样。
locale: params['de-DE']
到
locale: 'de-DE'
.
希望能帮到你!!!。
解决了
添加语言参数,像这样。
const speechOptions = {
speechRecognizer: new CognitiveServices.SpeechRecognizer({ subscriptionKey: 'XXXXX', locale: 'de-DE' }),
speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
gender: CognitiveServices.SynthesisGender.Female,
subscriptionKey: 'XXXXX',
voiceName: 'Microsoft Server Speech Text to Speech Voice (de-DE, KatjaNeutral)', location: 'de-DE'
})
};
现在机器人在WebChat中收听德文,以及上面提到的参数'de-DE'。