1

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

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

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

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

我的清单.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...');
        }
    });
}
4

1 回答 1

2

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

截屏

输出生成

清单.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"]
    }]
}
}

索引.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();

背景.js

function dummy() {

}
于 2012-11-20T14:31:31.430 回答