如何通过Microsoft Bot Framework Chatbot使用Google Speech to Text功能?

时间:2018-10-18 12:06:39

标签: botframework speech-to-text microsoft-cognitive google-speech-api

我想在基于Microsoft Bot Framework的聊天机器人中使用Google语音转文本功能, 基于Microsoft BorFramework的漫游器的常规实现如下:

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({ subscriptionKey: '0000SPEECHKEY00000000' }),
        speechSynthesizer: new CognitiveServices.SpeechSynthesizer({
            gender: CognitiveServices.SynthesisGender.Female,
            subscriptionKey: '0000SPEECHKEY00000000',
            voiceName: 'Microsoft Server Speech Text to Speech Voice (en-US, JessaRUS)'
        })
    };
    BotChat.App({
        bot: bot,
        locale: params['locale'],
        resize: 'detect',
        // sendTyping: true,    // defaults to false. set to true to send 'typing' activities to bot (and other users) when user is typing
        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'));

1 个答案:

答案 0 :(得分:1)

您可以在网络聊天中进行语音识别:

  • 使用Microsoft认知服务
  • 使用浏览器语音功能
  • 使用自定义语音识别

这里是第三个选项。您必须提供实现ISpeechRecognizer的自定义语音识别。

此界面详细说明:

export interface ISpeechRecognizer {
    locale: string;
    isStreamingToService: boolean;
    referenceGrammarId: string; // unique identifier to send to the speech implementation to bias SR to this scenario

    onIntermediateResult: Func<string, void>;
    onFinalResult: Func<string, void>;
    onAudioStreamingToService: Action;
    onRecognitionFailed: Action;

    warmup(): void;
    setGrammars(grammars?: string[]): void;
    startRecognizing(): Promise<void>;
    stopRecognizing(): Promise<void>;
    speechIsAvailable(): boolean;
}

来源:https://github.com/Microsoft/BotFramework-WebChat/blob/master/src/SpeechModule.ts

您还将在上方的链接中找到第二个选项BrowserSpeechRecognizer的实现