Download Google Chrome Latest Version Offline

Posts about google chrome

7 April 2017

Using Google Chrome Web Speech Api

google chrome web speech api Do google Chrome extensions support Chrome's Web Speech speech recognition API? I have included some javascript to create a speech recognition object, but when I launch my extension, I am not prompted for microphone access.

This is not an issue with my code. I have searched on google, but I can't find any information on whether Chrome extensions support the Web Speech API. I just want a yes/no answer.

Note: I believe the WebSpeech API won't work for local files.

Solution


Update: Based on RobW's answer, this answer is now out of date, and the Web Speech API is now usable inside of extensions. (Unfortunately, I can't delete this answer unless the OP un-accepts it.)

The answer is not yet. Pages accessed through chrome-extension: URLs cannot access any media-input APIs, including speechRecognition and getUserMedia. Any attempt to the use APIs will immediately trigger an error callback.

I originally thought speechRecognition could work like the geolocation API: extension popups cannot prompt for geolocation permission, but chrome-extension: pages loaded as full browser pages can prompt for permission just like a normal page. However, media APIs do not behave this way; they fail regardless of whether the page is a popup or a full page.

There is a bug report to fix this and allow developers to specify media-access permissions in the manifest. When this bug is fixed, extensions can have a manifest-set permission that grants them automatic microphone/video access, so the inability to prompt for permission will become a non-issue (and therefore extensions with appropriate manifest permissions will be able to freely use the Speech API).

Solution 2


The Web Speech API can already be used by Chrome extensions, even in the background page and extension button popups. The fact that it works is not necessarily an intended feature, and I have previously explained how it works and why it works in this answer to How to use webrtc insde google chrome extension?. The previous explanation is about WebRTC, but it applies equally to Web Speech, and can be used as follows:

Instantiate a webkitSpeechRecognition instance and start recording.
If a permission error is detected (onerror being triggered with event.error === 'not-allowed'), open an extension page (chrome-extension://[ID]/yourpage.html). This extension page can be opened in a new window, tab or iframe.
From this page, request access to the microphone. getUserMedia and SpeechRecognition both share the (persistent) audio permission, so to detect whether audio recording is allowed, you could use getUserMedia to request the permission without activating speech recognition. For instance:
navigator.webkitGetUserMedia({
    audio: true,
}, function(stream) {
    stream.stop();
    // Now you know that you have audio permission. Do whatever you want...
}, function() {
    // Aw. No permission (or no microphone available).
});
 

0 comments:

Translate

Powered by Blogger.