Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Ezequiel Jadib 6b3df2c0b3
Update documentation links to point to new docs (#118)
6 years ago
..
709257d79e
Adding SpeechToText Sample
7 years ago
74eb448cde
[Node] Update Emulator screenshots
7 years ago
1581e5e147
Updating API keys
7 years ago
6b3df2c0b3
Update documentation links to point to new docs (#118)
6 years ago
3b8f26a2fb
Node - Samples ES5 compliant
7 years ago
02a6c8b719
[Node] Update remaining API Keys and azuredeploy.json templates
7 years ago
28d163ecf6
[Node] Update to botbuilder 3.7.0 (#50)
7 years ago
3b8f26a2fb
Node - Samples ES5 compliant
7 years ago

README.md

You have to be logged in to leave a comment. Sign In

# 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.

Deploy to Azure

Prerequisites

The minimum prerequisites to run this sample are:

  • Latest Node.js with NPM. Download it from here.
  • The Bot Framework Emulator. To install the Bot Framework Emulator, download it from here. Please refer to this documentation article to know more about the Bot Framework Emulator.
  • Bing Speech Api Key. You can obtain one from Microsoft Cognitive Services Subscriptions Page.
  • [Recommended] Visual Studio Code for IntelliSense and debugging, download it from here for free.
  • This sample currently uses a free trial Microsoft Cognitive service key with limited QPS. Please subscribe to Bing Speech Api services here and update the MICROSOFT_SPEECH_API_KEY key in .env file to try it out further.

Usage

Attach an audio file (wav format).

Code Highlights

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:

  • speech-service.js: is the core component illustrating how to call the Bing Speech RESTful API.
  • app.js: is the bot service listener receiving messages from the connector service and passing them down to speech-service.js and doing text processing on them.

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);
            }
        }
    );
};

Outcome

You will see the following when connecting the Bot to the Emulator and send it an audio file and a command:

Input:

"What's the weather like?"

Output:

Sample Outcome

More Information

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:

Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...