带有node.js Bot框架的Skype语音识别API

时间:2017-06-30 12:33:39

标签: node.js botframework skype-bots

我使用skype客户端进行bot应用程序。我正在使用语音到文本

处理音频语音有两种模式:提及enter link description here BY dandriscoll

  1. 客户端记录一个小型音频文件(如WAV)并将其作为附件上传到机器人
  2. 客户端将音频流发送到bot
  3. 尽管客户支持各不相同,但大多数Bot Framework渠道都支持模式1。在这种情况下,您可以将WAV上传到Bing Speech API,它将返回转录结果。

    唯一支持模式2的Bot Framework渠道是Skype Calling。在这种情况下,您会收到一个音频流,并可以使用Bing语音客户端库来获取实时转录源。

    这里想要使用模式2示例代码

    var restify = require('restify');
    var builder = require('botbuilder');
    var calling = require('botbuilder-calling');
    var prompts = require('./prompts');
    var speechService = require('./speech-service.js');
    
    //=========================================================
    // Bot Setup
    //=========================================================
    
    // Setup Restify Server
    var server = restify.createServer();
    server.listen(process.env.port || process.env.PORT || 3978, function () {
       console.log('%s listening to %s', server.name, server.url); 
    });
    
    // Create chat bot
    var chatConnector = new builder.ChatConnector({
        appId: process.env.MICROSOFT_APP_ID,
        appPassword: process.env.MICROSOFT_APP_PASSWORD
    });
    var chatBot = new builder.UniversalBot(chatConnector);
    server.post('/api/messages', chatConnector.listen());
    
    // Create calling bot
    var connector = new calling.CallConnector({
        callbackUrl: 'https://example.in/api/calls',
        appId: process.env.MICROSOFT_APP_ID,
        appPassword: process.env.MICROSOFT_APP_PASSWORD
    });
    var bot = new calling.UniversalCallBot(connector);
    server.post('/api/calls', connector.listen());
    
    //=========================================================
    // Chat Dialogs
    //=========================================================
    // Add root dialog
    
    bot.dialog('/', function (session) {
        session.send('Headfitted Bot application... !');
        session.beginDialog('/record');
    });
    
    bot.dialog('/record', [
        function (session) {
            session.send(prompts.record.intro);
            calling.Prompts.record(session, prompts.record.prompt, { playBeep: true });
        },
        function (session, results) {
            if (results.response) {
                console.log(results.response.recordedAudio);
                session.endDialog(prompts.record.result, results.response.lengthOfRecordingInSecs);
    
            } else {
                session.endDialog(prompts.canceled);
            }
        }
    ]);
    

    当我运行上面的演示时,我在命令提示符

    中收到了响应
    { recordedAudio: <Buffer 30 26 b2 75 8e 66 cf 11 a6 d9 00 aa 00 62 ce 6c 3d 13 00 00 00 00 00 00 06 00 00 00 01 02 a1 dc ab 8c 47 a9 cf 11 8e e4 00 c0 0c 20 53 65 68 00 00 00 ... >,
    lengthOfRecordingInSecs: 2.581 }
    

    现在我想使用recordedAudio并传递给speech to text API函数。 stream 将是我的 recordedAudio

    speechService.getTextFromAudioStream(stream)
        .then(function (text) {
            session.send(processText(text));
        })
        .catch(function (error) {
            session.send('Oops! Something went wrong. Try again later.');
            console.error(error);
        });
    

    我搜索了谷歌和僵尸框架,但没有运气。