繁体   English   中英

如何在 QWebEngineView 中允许语音识别 api

[英]How to allow speech recogonition api in QWebEngineView

我有一个小代码

<!doctype html>
<head>
    <title>JavaScript Speech to Text</title>
</head>
<body>
    <h2>JavaScript Speech to Text</h2>
    <p>Click on the below button and speak something...</p>
    <p><button type="button" onclick="runSpeechRecognition()">Speech to Text</button> &nbsp; <span id="action"></span></p>
    <div id="output" class="hide"></div>
    <script>
        /* JS comes here */
        function runSpeechRecognition() {
            // get output div reference
            var output = document.getElementById("output");
            // get action element reference
            var action = document.getElementById("action");
            // new speech recognition object
            var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
            var recognition = new SpeechRecognition();
        
            // This runs when the speech recognition service starts
            recognition.onstart = function() {
                action.innerHTML = "<small>listening, please speak...</small>";
            };
            
            recognition.onspeechend = function() {
                action.innerHTML = "<small>stopped listening, hope you are done...</small>";
                recognition.stop();
            }
          
            // This runs when the speech recognition service returns result
            recognition.onresult = function(event) {
                var transcript = event.results[0][0].transcript;
                var confidence = event.results[0][0].confidence;
                output.innerHTML = "<b>Text:</b> " + transcript + "<br/> <b>Confidence:</b> " + confidence*100+"%";
                output.classList.remove("hide");
            };
          
             // start recognition
             recognition.start();
        }
    </script>
</body>

它不适用于 PyQtWebEngine 如何使其工作。

我搜索了一下,发现只有基于 chromium 的浏览器支持语音识别。

PyQtWebEngine 是基于 Chromium 的,那么如何使它工作

尽管此功能在铬中可用,但已被 Qt 禁用,如本报告所示。 也许在 Qt6 的以下版本中将启用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM