Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Speech Recognition with JavaScript
JoelBonetR 🥇
JoelBonetR 🥇

Posted on • Edited on

     

Speech Recognition with JavaScript

Cover image credits: dribbble

Some time ago,speech recognition API was added to thespecs and we gotpartial support on Chrome, Safari, Baidu, android webview, iOS safari, samsung internet and Kaios browsers (see browser support in detail).

Disclaimer: This implementation won't work in Opera (as it doesn't support the constructor) and also won't work in FireFox (because it doesn't support a single thing of it) so if you're using one of those, I suggest you to use Chrome -or any other compatible browser- if you want to take a try.

Speech recognition code and PoC

Edit: I realised that for any reason it won't work when embedded sohere's the link to open it directly.

The implementation I made currently supports English and Spanish just to showcase.

Quick instructions and feature overview:

  • Choose one of the languages from the drop down.
  • Hit the mic icon and it will start recording (you'll notice a weird animation).
  • Once you finish a sentence it will write it down in the box.
  • When you want it to stop recording, simply press the mic again (animation stops).
  • You can also hit the box to copy the text in your clipboard.

Speech Recognition in the Browser with JavaScript - key code blocks:

/* Check whether the SpeechRecognition or the webkitSpeechRecognition API is available on window and reference it */constrecognitionSvc=window.SpeechRecognition||window.webkitSpeechRecognition;// Instantiate itconstrecognition=newrecognitionSvc();/* Set the speech recognition to continuous so it keeps listening to whatever you say. This way you can record long texts, conversations and so on. */recognition.continuous=true;/* Sets the language for speech recognition. It uses IETF tags, ISO 639-1 like en-GB, en-US, es-ES and so on */recognition.lang='en-GB';// Start the speech recognitionrecognition.start();// Event triggered when it gets a matchrecognition.onresult=(event)=>{// iterate through speech recognition resultsfor(constresultofevent.results){// Print the transcription to the consoleconsole.log(`${result[0].transcript}`);}}// Stop the speech recognitionrecognition.stop();
Enter fullscreen modeExit fullscreen mode

This implementation currently supports the following languages for speech recognition:

  • en-GB
  • en-US
  • es-ES
  • de-DE
  • de-CH
  • fr-FR

If you want me toadd support for more languages tell me in the comment sections and I'm updating it in a blink so you can test it on your own language 😁

That's all for today, hope you enjoyed I sure did doing that

Top comments(22)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
polterguy profile image
Thomas Hansen
CEO at AINIRO.IO - Obsessed with ChatGPT, AI and Machine Learning. Delivering AI solutions and development platforms based upon No-Code and AI.
  • Location
    Cyprus
  • Work
    CEO and Founder of AINIRO Ltd
  • Joined

Cool. I once created a speech based speech recognition thing based upon MySQL and SoundEx allowing me to create code by speaking through my headphones. It was based upon creating a hierarchical “menu” where I could say “Create button”. Then the machine would respond with “what button”, etc. The thing of course produced Hyperlambda though. I doubt it can be done without meta programming.

One thing that bothers me is that this was 5 years ago, and speech support has basically stood 100% perfectly still in all browsers since then … 😕

CollapseExpand
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined
One thing that bothers me is that this was 5 years ago, and speech support has basically stood 100% perfectly still in all browsers since then … 😕

Not in all of them, (e.g. Opera mini, FireFox mobile), it's a nice to have in browsers, specially targeting accessibility, but screen readers for blind people do the job and, on the other hand, most implementations for any other purpose send data to a backend using streams so they can process the incoming speech plus use the user feedback to train an IA among others and without hurting the performance.

...allowing me to create code by speaking through my headphones...... I doubt it can be done without meta programming.

I agree on this. The concept "metaprogramming" is extense and covers different ways in which it can work (or be implemented) and from its own definition it is a building block for this kind of applications.

CollapseExpand
 
nngosoftware profile image
İbrahim Yaşar
Front-End Developer, Graphic Designer & Photographer
  • Location
    İstanbul, Turkey
  • Joined

This is really awesome. Could you please add the Turkish language? I would definitely like to try this in my native language and use it in my projects.

CollapseExpand
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

Added! 😁

CollapseExpand
 
nngosoftware profile image
İbrahim Yaşar
Front-End Developer, Graphic Designer & Photographer
  • Location
    İstanbul, Turkey
  • Joined

Thanks :)

CollapseExpand
 
venkatgadicherla profile image
venkatgadicherla
  • Location
    3000
  • Work
    Mr at StartUp
  • Joined

It's cool mate. Very good

CollapseExpand
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

Thank you! 🤖

CollapseExpand
 
venkatgadicherla profile image
venkatgadicherla
  • Location
    3000
  • Work
    Mr at StartUp
  • Joined

Can u add Telugu a Indian language:)

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

I can try, do you know the IETF/ISO language code for it? 😁

CollapseExpand
 
samuelrivaldo profile image
Samuelrivaldo
Student in web development and Programmation
  • Work
    Student
  • Joined

Thanks you 🙏. I'd like that you put in french too.

CollapseExpand
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

Done! 😁

CollapseExpand
 
mamsoares profile image
Marcelo Soares
I am a FullStack and Mobile Developer
  • Location
    Rio de Janeiro, RJ
  • Education
    Master Degree
  • Work
    FullStack and Mobile Developer
  • Joined

Thank you 🙏. I'd like that you put in Brazilian Portuguse too.

CollapseExpand
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

Added both Portugal and Brazilian portuguese 😁

CollapseExpand
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

Thank you! 😁

CollapseExpand
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

I added support for some extra languages in the mean time 😁

CollapseExpand
 
symeon profile image
Symeon Sideris
  • Work
    Technical Manager @ Gabrieli Media Group
  • Joined

Thank you very much for your useful article and implementation. Does it support Greek?
Have a nice (programming) day

CollapseExpand
 
joelbonetr profile image
JoelBonetR 🥇
Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

Hi Symeon, added support for Greekel-GR, try it out! 😃

CollapseExpand
 
arantisjr profile image
Arantis-jr
Learning coding......☑️💻
  • Education
    Cameroon
  • Work
    Student
  • Joined

Cool 😎

CollapseExpand
 
harshi_acchu_4352edeb84a6 profile image
Harshi Acchu
  • Joined

Could you pls add tamil in it

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Tech Lead/Team Lead. Senior WebDev.Intermediate Grade on Computer Systems-High Grade on Web Application Development-MBA (+Marketing+HHRR).Studied a bit of law, economics and design
  • Location
    Spain
  • Education
    Higher Level Education Certificate on Web Application Development
  • Work
    Tech Lead/Lead Dev
  • Joined

More fromJoelBonetR 🥇

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp