How to make a website speech-driven

bhawin parkeria
Globant
Published in
3 min readAug 2, 2022

Research is fruitful in software engineering life to have knowledge of what’s new in the software world. One such thing I have encountered in my research is NLP Compromise. It is a javascript library that can understand parts of speech from a sentence. Not just that, it can understand numbers, names and many more. More details: https://compromise.cool.

Now, let’s be specific to my work. I have built a shopping website where users can search for products through voice commands using web speech API https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API, I let users speak and convert that speech into text using web speech API.

Then I created 2 files in my backend server :

1: verbs.js to have a list of verbs which means to show the specific product

2: nouns.js will list the nouns (products) which I have in my database.

The processSpeechResult function shown in the first code image is actually calling the API with the speechResult. Now, the idea is to implement NLP Compromise to take out nouns and verbs from the speechResult and if the verbs match with something like “show”, “details”, “detail”. Then I will get the noun and search the database with the noun. To give you an example, let's say I spoke “show jackets” when the NLP compromise will decode this sentence, it will put jackets as a noun and show as a verb. Now ‘show’ matches with the verbs that I have in my list, so what I will do is start searching my database with ‘jackets’ (noun) and get the list of it and send it as a JSON response to the frontend.

Now comes the code where we are importing the NLP compromise and using it to get tokens of speech from sentences and match them with verbs and nouns. This is the code written in node js using express.

This is how I began working with NLP Compromise to make my shopping website speech-driven . Remember, this is just the beginning, I have seen a lot of useful functionalities in NLP compromise which makes the speech more understandable.

--

--