Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Cannot use WebRTC AudioCapture with WebEngineView connected to local server via WebKitSpeechRecognition



  • Hello. I am having trouble getting a WebEngineView to convert speech to text using the SpeechRecognition API.
    if I access the same page from chrome, the URL is able to correctly recognize speech, but in the Qt Web Engine View, it doesn't even appear to be accessing the microphone.

    This is on Qt 5.15.0 on Kubuntu (lastest). Other Qt components are able to detect and use the microphone, however the WebEngineView cannot. No errors are returned and under closer inspection of the Qt 5.15.0 source code, it seems to be setting the feature to -1 by default with Q_UNREACHABLE() before it.. not sure what this implies or if its relevant but..

    (From Qt 5.15 Source)
    5.15.0/Src/qtwebengine/src/webengine/api/qquickwebengineview.cpp

    static QQuickWebEngineView::Feature toFeature(QtWebEngineCore::ProfileAdapter::PermissionType type)
    {
        switch (type) {
        case QtWebEngineCore::ProfileAdapter::NotificationPermission:
            return QQuickWebEngineView::Notifications;
        case QtWebEngineCore::ProfileAdapter::GeolocationPermission:
            return QQuickWebEngineView::Geolocation;
        default:
            break;
        }
        Q_UNREACHABLE();
        return QQuickWebEngineView::Feature(-1);
    }
    
    
    void QQuickWebEngineViewPrivate::runFeaturePermissionRequest(QtWebEngineCore::ProfileAdapter::PermissionType permission, const QUrl &url)
    {
        Q_Q(QQuickWebEngineView);
        Q_EMIT q->featurePermissionRequested(url, toFeature(permission));
    }
    

    main.cpp

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    import QtWebEngine 1.10
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        WebEngineView {
            id: view
            anchors.fill: parent
            url: "http://127.0.0.1/audio.html"
            audioMuted: false
            onLoadingChanged: {
                if (!view.loading) {
                    console.log("Requesting audio capture")
                   // featurePermissionRequested(url, WebEngineView.MediaAudioCapture)
                    view.grantFeaturePermission(url,
                                                WebEngineView.MediaAudioCapture,
                                                true)
                }
            }
            onFeaturePermissionRequested: {
                view.grantFeaturePermission(securityOrigin, feature, true)
            }
    
            Component.onCompleted: {
    
            }
        }
    }
    

    audio.html

    ...
    window.rc = new webkitSpeechRecognition()
    
    window.rc.onresult = function(result) { 
    ...