安卓 WebView(WebChromeClient)语音合成未定义。

8
我正在尝试在我设置为WebChromeClient的Android WebView中使用Web语音合成API。然而,当我检查页面并运行以下命令时 console.log('speechSynthesis' in window, 'webkitSpeechRecognition' in window, 'speechRecognition' in window);每个都返回false,false,false。
如果我在Android上使用Chrome检查页面,则返回true,true,false。
通过Chrome应用程序的用户代理显示为:
"Mozilla/5.0(Linux; Android 8.1.0; Pixel 2 XL Build / OPM1.171019.018) AppleWebKit/537.36(KHTML、like Gecko)Chrome/64.0.3282.137移动版Safari/537.36"
Chrome WebView 显示为:
"Mozilla/5.0(Linux; Android 8.1.0; Pixel 2 XL Build / OPM1.171019.018; wv)AppleWebKit/537.36(KHTML、like Gecko)Version/4.0 Chrome/64.0.3282.137移动版Safari/537.36"
Chrome版本完全相同,但speechSynthesis不在窗口中。
我已经在webview上启用了以下设置:
    webViewSettings.setJavaScriptEnabled(true);
    webViewSettings.setAllowFileAccessFromFileURLs(true);
    webViewSettings.setAllowUniversalAccessFromFileURLs(true);
    webViewSettings.setAllowContentAccess(true);
    webViewSettings.setAllowFileAccess(true);
    webViewSettings.setDatabaseEnabled(true);
    webViewSettings.setMediaPlaybackRequiresUserGesture(false);

谢谢


我不知道安卓出了什么问题。所有的事情都看起来很困难。我已经搜索了一整天,但是仍然找不到任何有用的信息。据我所知,如果webview能够使用chrome渲染器进行渲染(但我找不到如何实现),那么这个问题就可以解决。 - Tudor
1个回答

0
代码是正确的,但你需要将代码从webViewSettings更改为webview.getSettings()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接