17

In documentation and tutorial for REST API (Google Sppech API for Node: https://cloud.google.com/nodejs/apis), so my question is how to use the Cloud Speech API in JavaScript. Someone used on any page with javascript?


2020-04-24 EDIT: The accepted answer is using webkitSpeechRecognition which is not available on mobile: https://stackoverflow.com/a/61039699/775359

Google documentation and examples: https://cloud.google.com/speech-to-text/docs/samples

Node.js code: https://github.com/googleapis/nodejs-speech/blob/master/samples/MicrophoneStream.js

REQUIREMENT: it has to run in Safari on iOS.

Mars Robertson
  • 12,673
  • 11
  • 68
  • 89
Thiago F. Toledo
  • 313
  • 1
  • 2
  • 10
  • I think you have the wrong idea about what the google cloud API's are all about - perhaps [this](https://developers.google.com/web/updates/2013/01/Voice-Driven-Web-Apps-Introduction-to-the-Web-Speech-API?hl=en) is closer to what you need – Jaromanda X Aug 05 '16 at 12:00
  • Did you acomplish this, with just javaScript? – Ivan Fontalvo Aug 25 '21 at 11:50

1 Answers1

11

The Google Cloud API is more specifically used for server-side speech processing. If you're looking to use voice recognition through a browser, you should use your browser's built in Web Speech API. Here's a simple example:

var recognition = new webkitSpeechRecognition();
recognition.continuous = true;

var output = document.getElementById('output');
recognition.onresult = function(event) {
  output.textContent = event.results[0][0].transcript;
};
<div id="output"></div>
<button onclick="recognition.start()">Start</button>
<button onclick="recognition.stop()">Stop</button>
fny
  • 31,255
  • 16
  • 96
  • 127
  • 5
    They are totally different API. Web Speech API you are suggesting is private API and has limitation of 50 requests a day! We cant use if for commercial projects with this limitations. Please go through https://www.chromium.org/developers/how-tos/api-keys before you make the decision of using Speech Web API – Paresh Varde Oct 07 '16 at 07:02
  • 1
    This simply isn't true. The [Web Speech API](https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html) is a W3C supported, a cross-browser feature that even exists in [Firefox](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API/Using_the_Web_Speech_API) today. It's up to the browser vendor decide how the speech is parsed, and the Google API keys come built into Google's Chrome builds by default. For a custom Chromium build, you would need to obtain API keys. – fny Oct 07 '16 at 20:40
  • @PareshVarde Again, that's for compiling your own Chromium build. I can easily make thousands of requests in a day from my own browser without any issues. Here's an example that makes 1 request every 3 seconds for 100 requests: https://jsbin.com/faxeyi – fny Oct 11 '16 at 19:24
  • 1
    I am not using Google Chrome. I am packaging my application into electron atom and it causes issue. Google Chrome works fine without any affecting any quota limit they specified. – Paresh Varde Oct 12 '16 at 12:59
  • Quick test using `webkitSpeechRecognition` in Chrome - rather poor quality. I'm keen to try Cloud version, opened a bounty of this question... – Mars Robertson Apr 27 '20 at 16:28