使用Google Chrome ttsengine进行语音输入

时间:2012-11-20 13:12:23

标签: google-chrome google-chrome-extension speech-recognition speech-to-text text-to-speech

我正在开发一个chrome扩展并使用tts和ttsengine进行语音i / o。但是我的扩展程序让我的Chrome崩溃而没有有用的错误代码(Chrome意外退出Process: Google Chrome [888]

当我调用javascript方法chrome.experimental.speechInput.start(function(){}) chrome崩溃时。

我尝试了谷歌提供的另一个扩展,即语音识别器,它运行良好,google.com中的语音输入效果也很好。实验标志已经设定。

是否有任何额外的许可或任何其他程序使言语到文本工作?

我的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"]
    }]
}
}

我的.js文件:

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...');
        }
    });
}

1 个答案:

答案 0 :(得分:2)

经过一些更改后,它对我的​​内容很有用。

<强> 截图

Out put Generated

<强>的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() {

}