Reputation: 609
I am developing a chrome extension and using tts and ttsengine for speech i/o. But my extension have my chrome to crash without a useful error code (Chrome quits unexpectedly with Process: Google Chrome [888]
)
When I call the javascript method chrome.experimental.speechInput.start(function(){})
chrome crashes.
I tried another extension provided by google which is Speech Recognizer and it works well, also the speech input in google.com works well. Experimental flag has been set.
Is there any additional permission to give or any other procedure to make speech-to-text work?
My manifest.json:
{
"name": "my_extension",
"version": "0.1",
"manifest_version": 2,
"description": "my description",
"icons": {
"16": "icon16.png",
"128": "icon128.png"
},
"app": {
"launch": {
"local_path": "/twitter/index.html"
}
},
"offline_enabled": true,
"permissions": [
"experimental",
"unlimitedStorage",
"https://api.twitter.com/*",
"ttsEngine",
"tts"
],
"tts_engine": {
"voices": [{
"lang": "de",
"event_types": ["end"]
}]
}
}
My .js file:
function startSpeechInput() {
chrome.experimental.speechInput.onError.addListener(recognitionFailed);
chrome.experimental.speechInput.onResult.addListener(recognitionSucceeded);
chrome.experimental.speechInput.onSoundEnd.addListener(recognitionEnded);
chrome.experimental.speechInput.isRecording(function (recording) {
if (!recording) {
chrome.experimental.speechInput.start({ 'language': 'en-US' }, function(){
//TODO
}
console.log("Voice recognition started!");
});
}
else {
console.log('Pressed Record while it is already recording. Do nothing...');
}
});
}
Upvotes: 1
Views: 1116
Reputation: 18534
It worked for me with your content after some changes.
Screenshot
Manifest.json:
{
"name": "my_extension",
"version": "0.1",
"manifest_version": 2,
"description": "my description",
"icons": {
"16": "icon.jpg",
"128": "icon.jpg"
},
"app": {
"launch": {
"local_path": "index.html"
}
},
"background":{
"scripts": ["background.js"]
},
"offline_enabled": true,
"permissions": [
"experimental",
"unlimitedStorage",
"https://api.twitter.com/*",
"ttsEngine",
"tts"
],
"tts_engine": {
"voices": [{
"lang": "de",
"event_types": ["end"]
}]
}
}
index.html
<html>
<head>
<script src="index.js">
</script>
</head>
<body>
</body>
</html>
index.js
function recognitionFailed(error) {
alert("Speech input failed: " + error.code);
}
function recognitionSucceeded(result) {
alert("Recognized '" + result.hypotheses[0].utterance + "' with confidence " + result.hypotheses[0].confidence);
}
function startSpeechInput() {
chrome.experimental.speechInput.onError.addListener(recognitionFailed);
chrome.experimental.speechInput.onResult.addListener(recognitionSucceeded);
chrome.experimental.speechInput.onSoundEnd.addListener(function (){
console.log("started");
});
chrome.experimental.speechInput.isRecording(function (recording) {
if (!recording) {
chrome.experimental.speechInput.start({ 'language': 'en-US' }, function(){
console.log("Voice recognition started!");
});
}
else {
console.log('Pressed Record while it is already recording. Do nothing...');
}
});
}
startSpeechInput();
background.js
function dummy() {
}
Upvotes: 2