2017-06-30 48 views
0

我正在使用skype客戶端進行bot應用程序。我使用的是語音到文本帶有node.js的Skype語音識別API Bot Framework

有兩種模式來處理音頻講話:提起enter link description here BY dandriscoll

  1. 客戶記錄一個小的音頻文件(如WAV),並上傳爲附接到機器人
  2. 客戶端發送的音頻流,以機器人

大多數機器人框架通道支撐圖案1中,雖然客戶端支持變化。在這種情況下,您可以將WAV上傳到Bing Speech API並返回轉錄結果。

支持模式2的唯一Bot Framework頻道是Skype Calling。在這種情況下,您會收到一個音頻流,並可以使用Bing Speech客戶端庫獲取實時轉錄源。

這裏要當我運行我接收在我的命令提示的響應上述演示用圖案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函數。 將是我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); 
    }); 

我做了谷歌搜索,BOT框架,但沒有運氣。

+0

有什麼問題嗎? –

+0

@PaulSturm問題是我如何可以將流媒體中的recordingAudio傳遞給speechService。 –

+0

花了一週的時間解決了這個問題後,我發現Bing Speech API只支持WAV/PCM。所以我已經開始將wma轉換爲wav文件,並將wav流傳遞給文本web api。使用ffmpeg。感謝https://github.com/Microsoft/BotBuilder-Samples/issues/52用戶pcostantini發佈 –

回答