JavaScript Speech Recognition

Поділитися
Вставка
  • Опубліковано 20 сер 2024
  • Today we learn how to use the built in Speech Recognition in the browser. Grab all the exercises and starter files over at JavaScript30.com

КОМЕНТАРІ • 93

  • @ufotofu9
    @ufotofu9 5 років тому +2

    So cool that you can do this with just a text editor and a browser! Love your videos. I've built six amazing projects today by watching this series. All of them are things that I would have considered way out of my ability level, but here they are, working. Thank you!

  • @msjogren
    @msjogren 5 років тому +1

    Great stuff! People are very slow to adapt to innovation. This video is a perfect example. It was done over a year ago and there is not much out there.

  • @joaopargana8983
    @joaopargana8983 5 років тому +2

    Man, this one was really nice!! Amazing! Thank you so much for these guides

  • @NeelanshMathur
    @NeelanshMathur 5 років тому +2

    Wow! It’s new to me and seems fascinating already!
    It was a good video 😊

  • @lonnybulldozer8426
    @lonnybulldozer8426 4 роки тому +3

    You could use this to learn how to say ternary.

  • @LePhenixGD
    @LePhenixGD 6 місяців тому

    You're an amazing tutor bruv!

  • @uzair004
    @uzair004 4 роки тому +1

    let transcript = e.results[0][0].transcript;
    this line seems to be working as well, instead of converting to array and then mapping through that array.

  • @martinjaskulla2363
    @martinjaskulla2363 6 років тому +3

    const transcript = e.results[0][0].transcript
    instead of
    const transcript = Array.from(e.results)
    .map(result => result[0])
    .map(result => result.transcript)
    .join("")
    seems also possible

    • @AndrewTSq
      @AndrewTSq 4 роки тому

      That works great :)

  • @thymarques
    @thymarques 4 роки тому

    It deliveries tons of new features for out apps!

  • @badarikrishna3169
    @badarikrishna3169 11 місяців тому

    While it's cool, in MDN docs it's clearly mentions that Chrome sends your speech data to servers for processing and it won't work without internet.
    So unfortunately I have to use tensorflowjs for inbox recognition.

  • @jilanbasha201
    @jilanbasha201 6 років тому

    Great tutorial, subscribed right after watching this one. Thanks a lot.

  • @LePhenixGD
    @LePhenixGD 5 місяців тому

    Just beware of that this Web API doesn't work on browsers other than Edge, Chrome, and Safari (it's a paid API provided by Google)

  • @SoulCalMusic
    @SoulCalMusic 4 роки тому +1

    As you mention towards the end, how would you make it only run the recognised function once, so it doesn't keep repeating?

  • @missgreendayfan
    @missgreendayfan 6 років тому +1

    Dammit I can't get it to work, but it seems to recognise the sound... so the problem isn't the microphone. I tried the finished one just to check if it was related to my code but nope :(

  • @GamingBirdBD
    @GamingBirdBD 6 років тому

    Thanks u a lot.....it's simply great!!!!

  • @macyyash5083
    @macyyash5083 4 роки тому +1

    I need source code of this tutorial. could anyone who made it ,send me please...

  • @taihatranduc8613
    @taihatranduc8613 4 роки тому

    thank you a lot. you are so awsome

  • @TheChosenSonOfGod
    @TheChosenSonOfGod 6 років тому

    If you use WebStorm, you don't need to have a server running; WebStorm creates its own for you.

  • @spytuber7765
    @spytuber7765 2 роки тому

    wow bless you dev😉

  • @AbsarNaeem1
    @AbsarNaeem1 4 роки тому

    This is only supported by Chrome. I'm using Opera for all the projects. Guess I'll have to skip this one out. But this is great stuff if it goes ahead from Experimental.

  • @trophydevice7624
    @trophydevice7624 3 роки тому

    I mainly use Brave Browser, and unfortunately it doesn't have speech recognition... Chrome worked fine for me.
    If anyone found a work around for Brave, please let me know!

  • @ihor1337
    @ihor1337 7 років тому +1

    Hi Wes,
    Thanks a lot for your time and effort you put into creating another great video for us. I have a few questions regarding the speech recognition.
    1). How many languages does it support?
    2). How does it decide which language to choose by default? Does it look at your system's locale settings, or browser settings, or maybe your Google account settings?
    3). Is it possible to set manually the language you'd like to use even if the system's locale is different? (ex. system locale settings are set to US but I want to use let's say a French language)
    4. Is it supported in any other browsers apart from Chrome?
    It would be highly appreciated if you could answer any of the questions above.
    Thanks again for your content.

    • @andreaamorosi231
      @andreaamorosi231 7 років тому +2

      Hey, maybe I can help
      1) It should support any of the ISO language codes you can use in the HTML lang attribute.
      2) It defaults to the HTML lang attribute value, or the user agent's language setting if that isn't set either.
      3) Yes, by using recognition.lang = 'fr'.
      4) It looks like it's currently supported only by Chrome.
      Check out MDN docs developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition for more info about the api and caniuse.com/#search=speechrecognition for detailed info about browser support.

    • @ihor1337
      @ihor1337 6 років тому

      Hey Andrea,
      Thanks a lot for answering and proving the useful links.

  • @marimuimoto3061
    @marimuimoto3061 6 років тому

    Hey there, I am quite new to js and I just started learning node/server-side js, so I was wondering if you actually needed to create a separate js file for your local host server. For example:
    // Dependencies
    var http = require("http");
    var fs = require("fs");
    // Set port to 8080
    var PORT = 8080;
    // Create server
    var server = http.createServer(handleRequest);
    // Create a function for handling requests and responses coming into server
    function handleRequest(req, res) {
    // Here we use the fs package to read our index.html file
    fs.readFile(__dirname + "/index.html", function(err, data) {
    // We then respond to the client with the HTML page by specifically telling the browser that we are delivering
    // an html file.
    res.writeHead(200, { "Content-Type": "text/html" });
    res.end(data);
    });
    }
    (add some other stuff)
    // Starts server
    server.listen(PORT, function() {
    console.log("Server is listening on PORT: " + PORT);
    });
    and of course all of the node modules and npm packages. Any help regarding running the app with a server would be greatly appreciated. Thanks so much!!

  • @olamide333
    @olamide333 6 років тому +1

    I'm having trouble with getting any text to show in the console on Windows. The innerHTML is not updating, so to print e.result is not even working. My mic is being picked up in the browser and I've run the npm commands, apache on xampp is running, not sure what I'm doing wrong. Any ideas?

    • @danbuild977
      @danbuild977 6 років тому

      Could you Codepen it? I and the rest of the comment section can have a look at the code for you

  • @khandelwalsahaj36
    @khandelwalsahaj36 5 років тому

    How do we change paragraph? What do we need to speak?

  • @misakikoonce1551
    @misakikoonce1551 4 роки тому

    I keep receiving an error 'SpeechRecognition' is not defined no-undef. I use chrome and I'm using webpack to access a server. This error might be because of webpack but can anyone help me? Here is my main.js looks like (following Wes Bos's code):
    (function() {
    window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
    const recognition = new SpeechRecognition();
    recognition.interimResults = true;
    let p = document.createElement('p');
    const words = document.querySelector('.words');
    words.appendChild(p);
    recognition.addEventListener('result', event => {
    const transcript = Array.from(event.results)
    .map(result => result[0])
    .map(result => result.transcript).join('');
    // Create a new container if you make a pause.
    if (event.results[0].isFinal) {
    p = document.createElement('p');
    words.appendChild(p);
    }
    p.textContent = transcript;
    });
    recognition.start();
    // Start recognition after each pause
    recognition.addEventListener('end', recognition.start);
    }());

  • @mirage4731
    @mirage4731 3 роки тому

    why it keeps on asking me permission to use mic

  • @mobcomparison6360
    @mobcomparison6360 Рік тому

    How stop recognition

  • @mustafaanas5991
    @mustafaanas5991 4 роки тому +1

    this is still not supported in Firefox. Annoying
    But thnx man, this is amazing

    • @DAROM-TK
      @DAROM-TK 3 роки тому

      I have error in Firefox, network error. May be you know, how fix this bug?

  • @peterchen1774
    @peterchen1774 6 років тому

    That's really cool~!!!!

  • @MrCwatchMan
    @MrCwatchMan 2 роки тому

    why didn't it work? Did something change?

  • @expukpuk
    @expukpuk 4 роки тому

    Thanks mate.

  • @hkj4714
    @hkj4714 6 років тому

    Im new to programming and I was wondering what I have to watch/do or if I even need that outher stuff that is there from the beginning.

    • @danbuild977
      @danbuild977 6 років тому

      HI Gurgamel,
      I hope that I can answer this. The code that is in the index-Start.html file from that beginning of the lesson is necessary to this lesson also.
      Wes, is simply reviewing the key final pieces of the puzzle. To cut down on lesson length and repetition of information.
      Does that all make sense?

  • @alex123bob
    @alex123bob 6 років тому

    Does Safari support this feature, and what about others like MicroSoft's Edge?

  • @jaronkunkel
    @jaronkunkel 3 роки тому

    I can't get my app to accurately recognize Spanish speech. I don't want all the code here, but does anyone know if maybe the Spanish is just not that accurate? If so I'll stop banging my head against that wall and just use English.

  • @hzg1364
    @hzg1364 2 роки тому

    how can stop that !??

  • @smitmirani5245
    @smitmirani5245 5 років тому +1

    your video is great
    but I have a doubt ,
    how can I export this text in another js file.
    THANK YOU

    • @eccdaba
      @eccdaba 5 років тому

      fs -- FileSystem the node module.

  • @navidshahed9120
    @navidshahed9120 4 роки тому

    Hello. First of all, Im sorry because my english not very good ;) then:
    I wirte this codes in my pc with xampp program and I have 2 problems:
    1. In local host, this codes run correctly, but, when I upload this codes in my site, dont run!
    2. If I open my site in Samsung internet browser, this codes run, but 1000 times request access for alow to use from microphon and I can afew talk then write.

  • @Webeli
    @Webeli 6 років тому

    Love it!

  • @jazimabbas8168
    @jazimabbas8168 3 роки тому

    all this browsers support this or not ? or should we go for some external apis like google or microsoft ??

  • @subokuleen
    @subokuleen 5 років тому

    For the transcript, the below code works well:
    const transcript = e.results[0][0]['transcript'];
    I don't know why we should turn transcript into array then join?

    • @GMPGIRI
      @GMPGIRI 5 років тому +1

      each of the possible translations from speech to text is stored as an index in a 2d array.

  • @Elduque40
    @Elduque40 7 років тому

    that was awesome

  • @sivakumark5374
    @sivakumark5374 4 роки тому

    is this one works for codova - hybrid app? any other solution plz. tahnx

  • @daoudaseye3018
    @daoudaseye3018 6 років тому

    Seems not working on Android chrome. Any ideas???

  • @glenmoreilagan6317
    @glenmoreilagan6317 6 років тому

    Sir how to create search engine using voice recognition?

  • @arletpaz8010
    @arletpaz8010 3 роки тому

    im sorry but is this for off-line ? or do i need to be in a network

  • @anwerammar6021
    @anwerammar6021 4 роки тому

    please , i need to know is that free ? , if i use that in video call app ? because i found on google cloud website , i have to pay if i use it for more than 60 mins but it didn't ask for a keyy

  • @dimitarvel1441
    @dimitarvel1441 5 років тому

    Well it's time to put voice control to my website. I am not sure how smart it is but hey, it's a competition. If face Id didn't win it last year, this doesn't have much chance but this combined with image recognition I think will be enough. We will see.

    • @dimitarvel1441
      @dimitarvel1441 5 років тому

      @@tika5635 last year I made an entire API in python with openCV and tensorflow for face identification.... I am a highschool student btw. I got beat by a girl which had a combustor which probably took her 2 weeks to make. Reasons:
      1 she was a girl
      2 she is wealthy and goes to a private school
      3 they thought I downloaded the software (even though I shared the entire code and documented the progress of every day on my chsngelog)
      4 I had won the year before that with my smart house prototype project using Arduino
      So this year I am making a web app for online learning that will use voice control for interface interaction. It won't be really that complex. I will give it a trigger word of "smart assistant" and it takes the words after that in a command string, which I will explode into every individual word and work out some AI solution which will compare those individual strings and try to find out which command out of an array of commands the user has given.

    • @dimitarvel1441
      @dimitarvel1441 5 років тому

      @@tika5635 also are you Bulgarian or otherwise Eastern European?

  • @Mougenenot211
    @Mougenenot211 6 років тому

    hey, I couln't find the server, how can I do it?

  • @09487abc
    @09487abc 4 роки тому

    i didn't see the source code, does anyone saw where could find this project's source code?

    • @zainnm86
      @zainnm86 3 роки тому

      you can sign up for his course (which includes this lesson with source code) for free. Just search for Javascript30 wes bos course

  • @ayushkumarverma6895
    @ayushkumarverma6895 6 років тому

    What font do you use in ur IDE?

  • @10MileLongPoo
    @10MileLongPoo 5 років тому

    nice that music

  • @shreyjainhere
    @shreyjainhere 6 років тому

    Mine is not working .. please find the below code .. Could any one please help me where i was wrong??
    Speech Detection
    window.SpeechRecognition = window.SpeechRecognition || Window.webkitSpeechRecognition;
    const recognition = new SpeechRecognition();
    recognition.interimResults= true;
    recognition.lang = 'en-US';
    let p = document.createElement('p');
    const words = document.querySelector('.words');
    words.appendChild(p);
    recognition.addEventListner('result', e =>{
    const transcript = Array.from(e.results)
    .map(result => result[0])
    .map(result => result.transcript)
    .join('');
    p.textContent = transcript;
    if (e.results[0].isFinal) {
    p=document.createElement('p');
    words.appendChild(p);
    }
    console.log(transcript);
    });
    recognition.addEventListner('end', recognition.start);
    recognition.start();
    html
    {
    font-size: 10px;
    }
    body
    {
    background:#ffc600;
    font-family: 'helvwtica neue';
    font-weight: 200;
    font-size: 20px;
    }
    .words{
    max-width:500px;
    margin:50px auto;
    background:white;
    border-radius:5px;
    box-shadow:10px 10px 0 rgba(0,0,0,0.1);
    padding:1rem 2rem 1rem 5rem;
    background: -webkit-gradient(linear, 0 0, 0 100%, from(#d9eaf3), color-stop(4%, #fff)) 0 4px;
    background-size: 100% 3rem;
    position: relative;
    line-height:3rem;
    }
    p {
    margin: 0 0 3rem;
    }
    .words:before {
    content: '';
    position: absolute;
    width: 4px;
    top: 0;
    left: 30px;
    bottom: 0;
    border: 1px solid;
    border-color: transparent #efe4e4;
    }

    • @teranceedmonds9026
      @teranceedmonds9026 5 років тому

      hey there here i uploaded the correct code...u have done a little grammar mistakes

      Speech Detection
      window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
      const recognition = new SpeechRecognition();
      recognition.interimResults= true;
      recognition.lang = 'en-US';
      let p = document.createElement('p');
      const words = document.querySelector('.words');
      words.appendChild(p);
      recognition.addEventListener('result', e =>{
      const transcript = Array.from(e.results)
      .map(result => result[0])
      .map(result => result.transcript)
      .join('');
      p.textContent = transcript;
      if (e.results[0].isFinal) {
      p=document.createElement('p');
      words.appendChild(p);
      }
      console.log(transcript);
      });

      recognition.addEventListener('end', recognition.start);
      recognition.start();
      html
      {
      font-size: 10px;

      }
      body
      {
      background:#ffc600;
      font-family: 'helvwtica neue';
      font-weight: 200;
      font-size: 20px;
      }
      .words{
      max-width:500px;
      margin:50px auto;
      background:white;
      border-radius:5px;
      box-shadow:10px 10px 0 rgba(0,0,0,0.1);
      padding:1rem 2rem 1rem 5rem;
      background: -webkit-gradient(linear, 0 0, 0 100%, from(#d9eaf3), color-stop(4%, #fff)) 0 4px;
      background-size: 100% 3rem;
      position: relative;
      line-height:3rem;
      }
      p {
      margin: 0 0 3rem;
      }
      .words:before {
      content: '';
      position: absolute;
      width: 4px;
      top: 0;
      left: 30px;
      bottom: 0;
      border: 1px solid;
      border-color: transparent #efe4e4;
      }

  • @moetechsauce
    @moetechsauce 4 роки тому

    does this work on all browsers ?

  • @webguys7051
    @webguys7051 5 років тому

    I got is to work.
    One small problem.. If the browser is in another language, it will only recognize the words that are in the same language as the broweser.
    For example, my phone's chrome is in Hebrew so it does not understand the English words.
    Same page on my pc - Chrome is in English - it understands only English...
    Is there a fix for this?

    • @pablowbk
      @pablowbk 5 років тому

      you can set the language, as Wes does with interimResults. here's my code as a reference:
      // initial set up
      const recognition = new SpeechRecognition();
      recognition.interimResults = true;
      recognition.lang = 'en-US';
      recognition.maxAlternatives = 1;
      you'lll need to find in the docs, how's hebrew described so you can assign it to recognition.lang = 'hb-HW' somehting like that

    • @edwardnortmann2489
      @edwardnortmann2489 2 роки тому +1

      @@pablowbk thanks a lot.. I've been looking for this

  • @2ksportsclutch216
    @2ksportsclutch216 5 років тому

    I am a developer which develop without an internet and speechrecognition seems dont work without internet...
    In recognition.onerror it return network error

    • @erikramirez7210
      @erikramirez7210 5 років тому

      In chrome, the API uses google cloud, so yeah it needs internet access. You can try pocketsphinx.js for an offline soluction.

    • @moshoodadedolapoadegbolu611
      @moshoodadedolapoadegbolu611 4 роки тому

      I tried downloading the pocketsphinx.js zip but don't know how to go about it, can you please explain more with a link or an example tutorial?

  • @tristancharie8711
    @tristancharie8711 6 років тому

    Why SpeechRecognition doesn't work for mobile ?
    Also it work only on localhost :(
    Thanks for help

    • @subokuleen
      @subokuleen 5 років тому

      It only support on chrome or android: developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition#Browser_compatibility

  • @Oumassabio
    @Oumassabio 3 роки тому

    Give mi simple site code

  • @satyensingh1881
    @satyensingh1881 5 років тому

    Wow awesome code can you shared code

  • @ufotofu9
    @ufotofu9 5 років тому

    Here's what you can use for the 🦄 unicorn!

  • @faisalimtiaz4390
    @faisalimtiaz4390 5 років тому

    When i try to run it with cordova app. It always gives me Network error.
    Can you solve this please

    • @erikramirez7210
      @erikramirez7210 5 років тому

      Make sure to use whitelist plugin and add an entry for any origin *

    • @faisalimtiaz4390
      @faisalimtiaz4390 5 років тому

      @@erikramirez7210 Got it. Trying

  • @Startoucharavos
    @Startoucharavos 6 років тому

    gives error on angular component

    • @webguys7051
      @webguys7051 5 років тому

      Because angular and jQuery do not work together...

  • @Oumassabio
    @Oumassabio 3 роки тому

    ♥️♥️♥️♥️♥️

  • @laxmikantyadav3988
    @laxmikantyadav3988 5 років тому

    Hi,
    Does it work on chromium browser ?

    • @erikramirez7210
      @erikramirez7210 5 років тому +1

      Yes, but you have to generate some free keys

  • @syediqbalahmed3176
    @syediqbalahmed3176 4 роки тому

    see later

  • @jimmydanger5749
    @jimmydanger5749 6 років тому

    WDF

  • @EdgardoAntonioRodasGomez
    @EdgardoAntonioRodasGomez 2 місяці тому

    O:

  • @feelingeverfine
    @feelingeverfine 7 років тому

    Hey Wes,
    I've taken the two speech tutorials and used them to make a "hal9000" that will speak back to you but I'm having an issue.
    If I say hello, it says hey back which then kicks off another hey, and another...
    I've tried to combat this by adding a start, and stop event to the speechsynthesisutterance which stops and starts the recognition.
    The only problem is, when there is no response (msg.text = "") the start never fires which means the recognition never stops and starts back up.
    Now the problem is, since Chrome shuts recognition off after a while I have to add another event to fire on recognition end to restart it.
    This screws up everything by trying to restart started recognition...
    I have been messing with this all day and can't figure it out.
    Can you provide any help?
    Thank you!!!
    github.com/davidhenley/hal9000

    • @jaapdebouw7410
      @jaapdebouw7410 6 років тому

      David Henley your project looks cool! Did you allready fix your problem?

    • @danbuild977
      @danbuild977 6 років тому

      Have you got this line in your code?
      recognition.addEventListener('end', recognition.start);
      Sorry if that is a really dumb questions, you are fields ahead of me.

  • @andresmontoya7852
    @andresmontoya7852 7 років тому

    Hi! Great application, but how can I add Speech recognition Depending of the country, for example, "Es_Co", "En_Us" and like this...