简体   繁体   中英

How to allow speech recogonition api in QWebEngineView

I have a small code

<!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>

It does not work on PyQtWebEngine How to make it work.

I searched for it and found that only chromium based browser supports speech recogonition.

PyQtWebEngine is Chromium Based then How to make it work

Although this feature is available in chromium but it has been disabled by Qt as indicated in this report . Maybe in the following versions of Qt6 it will be enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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