Code Monkey home page Code Monkey logo

speech-to-text-converter's Introduction

Google Speech to text REST API implementation using Recorder.js:

Google speech to text API used along with Recorder.js library.It will take audio from Microphone and passes the audio data to Google API Explorer API(REST API).We have used Recorder js library for recording audio through Microphone and Store into Browser in memory database which is called as "Blob" data as audio format.Also shows the recording list after recording has been done.

As Google API accept content data in base64 String format.Now we have converted blob data into base64 format and will send to api.To use REST api samples or you can test API using Google API explorer.

Google API explorer-REST API

Compatablity Instructions:

It will work on all lastest Browsers for eg.Chrome(Version 47+)

Note: Always run project under #### https: protocol beacause it will not allow to pass audio data from Microphone on in secure Channel.If you use under http: protocol then it will not allow to microphone to capture voice i.e Microphone will not start recording.

Always check Microphone setting in Browser:

setting > content settings > Microphone >

Usage Instructions:

Google Speech API Access

For Google Cloud speech API use you need API KEY to access API's: Follow Instructions to generate API key to access API:

  1. GO to Google Console
  2. Create new project or use existing project
  3. Goto API Service > Credential
  4. Create Credentials >API KEY

Recorder.js

This file contains all the logic related from recording to send data to API. Refrerence Recorder library github

Some important points related to recorder.js:

It always use 2 channel by deafult for recording using microphone.So Google speech api only accept this Mono(1) channel audio.Otherwise Google will throw Invalid data

Formatting Audio to BASE 64(How to Convert Audio to Base64 using JavaScript)

  function convertToBase64(blob){
    // encode base64
    var reader = new FileReader();
    reader.readAsDataURL(blob); 
    reader.onloadend = function() {
        base64data = reader.result;                
        console.log(base64data);
        base64AudioFormat=base64data;
        console.log("base 64 data",base64AudioFormat);
    }
    // 
}

Note:

Google API Accept request as JSON format according to audio files ,we have to pass encoding,Samplerates and langauage option for conversion.For detailed information you can refer following links:

Google Cloud Speech

For our project we are passing .Wav file data to Google Following Sample rate

 function execute() {
      console.log("audio_url",url);
    return gapi.client.speech.speech.recognize({
      "resource": {
        "audio": {
                      "content": base64AudioFormat
                       //"uri":url

                },
          "config": {
                "enableAutomaticPunctuation": true,
                "encoding": "LINEAR16",
                "languageCode": "en-US",
                "sampleRateHertz": 44100
              
  }
      }
    })
        .then(function(response) {
                // Handle the results here (response.result has the parsed body).
                console.log("Response", response);
                //responseData.result.results[0].alternatives[0].transcript
                document.getElementById("note_area").innerHTML=response.result.results[0].alternatives[0].transcript + " "
              
              },
              function(err) { console.error("Execute error", err); });
  }

SampleRateHertz for: .FLAC -> 16000 .Wav -> 44100

Steps to Run this project:

  1. Open index.html in browser.
  2. Click "Start Recording" button for start recording.
  3. Wait for 10 sec Recording automatically stopped and send base64 data to Google api and response will come.
  4. It will display list of Recording list where you can play and download file.
  5. In Case After base64 generation are taking time and Speech api will throws 400 Bad request.You can use "execute" button for sending data to API again.It will work properly.

speech-to-text-converter's People

Contributors

lifecoder123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

speech-to-text-converter's Issues

Speech to Text Without clicking on Execute button

Can you please convert speech to text without clicking on execute button ?.
I want the code which convert speech to text without clicking on execute button. Can you please share the same code for it. Here i have to click on excute button in order to convert speech to text.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.