top of page

Speech to Text API in Lightning

In this post, I will be showing how speech recognition can be added in Salesforce Lightning UI using Google's Speech API.

Hot Leads Lightning Component

The JavaScript Web Speech API allows spoken text to be converted into written text in a web browser. You can speak into a microphone and the API will translate speech to text.

Its one of the easiest ways to integrate speech recognition in Salesforce because it does not require any authentication. However, it does have cons. You are only limited to 50 queries per day and It only works on Chrome version 25 or later and Firefox.

To add voice you should initiate SpeechRecognition & webkitSpeechRecognition interfaces in JavaScript. SpeechRecognition is for Chrome and webkitSpeechRecognition is for FireFox.

In Salesforce, I had to use a Visualforce page as the interfaces or the browser's window object is not recognized in the Lightning component JavaScript controller. The page is embedded on the page layout using the Visualforce standard lightning component.

The records are retrieved from Leads object and displayed on the component. You have to click the mic button for the API to listen. After the conversion from voice to text, you have a string to work with. From there on, you can create your own logic to handle speech. My solution looks for an action word and first name(s), from that point on it will take appropriate action. There are loops in this solution, however, this POC was only to figure out how the API works.

Lightning App Builder, Visualforce Lightning Component

This API opens up an opportunity to easily add voice capability to business use cases.


Code Repo:


Featured Posts
Recent Posts
Search By Tags
No tags yet.
Follow Me
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page