【问题标题】:Using Google Chrome ttsengine for speech input使用谷歌浏览器 ttsengine 进行语音输入
【发布时间】:2012-11-08 13:33:24
【问题描述】:

我正在开发一个 chrome 扩展并使用 tts 和 ttsengine 进行语音输入/输出。但是我的扩展程序让我的 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...');
        }
    });
}

【问题讨论】:

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


    【解决方案1】:

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

    截图

    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() {
    
    }
    

    【讨论】:

    • 感谢您的帮助。我不知道出了什么问题,但它仍然崩溃。同样在我朋友的 chrome 中(我的是 mac,他有一台 windows 机器) js 代码片段也应该在控制台上运行,但是当我复制粘贴您修改的 index.js 文件时,它会崩溃。您是否启用了任何其他标志而不是实验性的?或者知道我的 chrome 会出现什么问题?
    • 你指的是哪个控制台??您如何在控制台上进行测试。顺便说一句,我也在 Mac 上。
    • 嗯,好吧。我的意思是 chrome 调试器中的 javascript 控制台
    • 你可以尝试添加最新的清单文件和background.js(我现在已经添加),它现在不会崩溃了。
    • 是的,我现在终于有了一个不会崩溃的扩展程序 :) 谢谢。我忽略了背景属性,因为没有明确表示它包含在 ttsengine 页面上的清单中,但现在添加了该选项,它可以正常工作。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多