gpt4 book ai didi

javascript - Android WebView (WebChromeClient) 语音合成未定义

转载 作者:行者123 更新时间:2023-12-03 16:40:28 29 4
gpt4 key购买 nike

我正在尝试在我设置为 WebChromeClient 的 Android WebView 中使用 Web Speech Synthesis API。但是,当我检查页面并运行以下命令时console.log('speechSynthesis' in window, 'webkitSpeechRecognition' in window, 'speechRecognition' in window);每个都返回为假、假、假。

如果我在 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 Mobile 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 Mobile 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);

谢谢

最佳答案

代码是正确的,但您需要从 webViewSettings 更改代码至webview.getSettings()

关于javascript - Android WebView (WebChromeClient) 语音合成未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48811263/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com