Are you sure you want to delete this access key?
# Speech To Text Bot Sample
A sample bot that illustrates how to use the Microsoft Cognitive Services Bing Speech API to analyze an audio file and return the text.
The minimum prerequisites to run this sample are:
MICROSOFT_SPEECH_API_KEY
key in .env file to try it out further.Attach an audio file (wav format).
Microsoft Cognitive Services provides a Speech Recognition API to convert audio into text. Check out Bing Speech API for a complete reference of Speech APIs available. In this sample we are using the Speech Recognition API using the REST API.
The main components are:
In this sample we are using the API to get the text and send it back to the user. Check out the use of the speechService.getTextFromAudioStream(stream)
method in app.js.
if (hasAudioAttachment(session)) {
var stream = getAudioStreamFromMessage(session.message);
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);
});
}
And here is the implementation of speechService.getTextFromAudioStream(stream)
in speech-service.js
exports.getTextFromAudioStream = function (stream) {
return new Promise(
function (resolve, reject) {
if (!speechApiAccessToken) {
try {
authenticate(function () {
streamToText(stream, resolve, reject);
});
} catch (exception) {
reject(exception);
}
} else {
streamToText(stream, resolve, reject);
}
}
);
};
You will see the following when connecting the Bot to the Emulator and send it an audio file and a command:
Input:
Output:
To get more information about how to get started in Bot Builder for Node and Microsoft Cognitive Services Bing Speech API please review the following resources:
Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?