Working with the Speech API
Hi everyone! this is more of an inquiry.
I am trying to write a bot who can receive audio inputs and returns back the text transcripts for further processing.
I am not a C# guy, but have developed couple of bots in nodejs using the bot builder framework. Somehow, I do not see any direct integration of the new Cognitive Services features with the bot builder framework. Is there any sample nodejs bot application which includes Speech Recognition or other Bing APIs ?
Thanks.
@officialdharam I developed Skype calling bot and did not find any embedded integration either. So I had to use Speech-To-Text service to transcribe the audio input. Unfortunately, this badly impacts performance and significant delay is noticed on the client, thus making the UX very poor.
True!
I have a bot with DirectLine channel and currently I use the speech.js to upload an audio file to get text. Then I send the text to the bot.
Unfortunately, I didn't get the microphone working for a real time scenario in a static speech.js file. When I host the visual studio solution on localhost and then try the microphone, it works fine. Did you get the microphone working with just speech.js file?
I use C# SDK. I implement the Skype use case so in real life I have no access to client and get the recorded audio complete after speech recording ended. Therefore, real time transcription is not possible in my case.
Hi @mghimp and @officialdharam, I'm not an expert in speech, but I can probably help you get started.
There are two patterns for dealing with audio speech:
- client records a small audio file (like a WAV) and uploads it as an attachment to the bot
- client sends an audio stream to the bot
Most Bot Framework channels support pattern 1, although client support varies. In this situation, you can upload the WAV to the Bing Speech API and it will return a transcribed result.
The only Bot Framework channel to support pattern 2 is Skype Calling. In this situation, you receive an audio stream and can use the Bing Speech client libraries to get a live transcription feed.
There are now samples on converting an audio file to text: https://github.com/Microsoft/BotBuilder-Samples/tree/master/CSharp/intelligence-SpeechToText https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/intelligence-SpeechToText
In Node.js, we've solved this with a bot middleware that calls the Bing Speech API (https://github.com/palmerabollo/bingspeech-api-client) for the STT, and passes the text to the bot, that can return it back to the user. It works really well.
how can I integrate speech api with bot?
Please look at the linked samples and if they don't work for you, create a new issue.
@chrimc62 Is there example how to use SpeechToText in bot that uses mixed input (text and voice)? I see that you pass transcription to session.send but what if I would like to use this text with Luis or regexp?
@dandriscoll As you mention two patterns for dealing with audio speech. I would like to implement the 2nd option 2. client sends an audio stream to the bot. The only Bot Framework channel to support pattern 2 is Skype Calling. In this situation, you receive an audio stream and can use the Bing Speech client libraries to get a live transcription feed.
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);
session.endDialog(prompts.record.result, results.response.lengthOfRecordingInSecs);
} else {
session.endDialog(prompts.canceled);
}
}
]);
I received an response in my console.
{ 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 }
but I want to pass the actual audio to the speechService API to convert speech to text.
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);
});
Question is how can I get the recoded audio/stream.