首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Android中加载页面时,ResponsiveVoice无法工作

在Android中加载页面时,ResponsiveVoice无法工作
EN

Stack Overflow用户
提问于 2017-05-20 19:52:18
回答 1查看 1.7K关注 0票数 0

当我单击按钮时,它工作得很好:

代码语言:javascript
运行
复制
<!DOCTYPE html>
<html>
<head>


    <script src="https://code.responsivevoice.org/responsivevoice.js"></script>

    </head >

<body>

<button onclick="responsiveVoice.speak('Welcome to the Responsive Voice website');">Click</button>

</body>
</html>

但当网页载入网页时,当我想播放演讲时,它就不起作用了:

代码语言:javascript
运行
复制
<!DOCTYPE html>
<html>
<head>

    <script src="https://code.responsivevoice.org/responsivevoice.js"></script>

    </head >

<body>

<script>

   setTimeout(responsiveVoice.speak("Welcome to the Responsive Voice  website"),500);

</script>
</body>
</html>

Android代码:

代码语言:javascript
运行
复制
public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebView webView = (WebView) findViewById(R.id.myWebview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("file:///android_asset/index.html");


    }

舱单档案:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.abdallah.test">

    <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission  android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

当我单击按钮时,这是系统的日志:

代码语言:javascript
运行
复制
I/chromium: [INFO:CONSOLE(62)] "Voice support NOT ready", source: https://code.responsivevoice.org/responsivevoice.js (62)
I/chromium: [INFO:CONSOLE(62)] "Voice support NOT ready", source: https://code.responsivevoice.org/responsivevoice.js (62)
I/chromium: [INFO:CONSOLE(62)] "Voice support NOT ready", source: https://code.responsivevoice.org/responsivevoice.js (62)
I/chromium: [INFO:CONSOLE(63)] "RV: speechSynthesis present but no system voices found", source: https://code.responsivevoice.org/responsivevoice.js (63)
I/chromium: [INFO:CONSOLE(64)] "RV: Enabling fallback mode", source: https://code.responsivevoice.org/responsivevoice.js (64)
D/MediaResourceGetter: ethernet/wifi connection detected
D/MediaHTTPConnection: filterOutInternalHeaders: key=User-Agent, val= SonyD5803 Build/23.4.A.1.232 stagefright/1.2 (Linux;Android 5.1.1)
D/MediaHTTPConnection: proxy null port 0
D/MediaResourceGetter: resource doesn't have video
D/MediaResourceGetter: extracted valid metadata: MediaMetadata[durationInMilliseconds=0, width=0, height=0, success=true]
E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
D/MediaPlayer: Couldn't open file on client side, trying server side
D/MediaHTTPConnection: filterOutInternalHeaders: key=User-Agent, val= SonyD5803 Build/23.4.A.1.232 stagefright/1.2 (Linux;Android 5.1.1)
D/MediaHTTPConnection: filterOutInternalHeaders: key=allow-cross-domain-redirect, val= false
D/MediaHTTPConnection: filterOutInternalHeaders: key=x-wap-profile, val= http://uaprof.sonymobile.com/D5803R2321.xml
D/MediaHTTPConnection: proxy null port 0
E/MediaPlayer: Should have subtitle controller already set
D/MediaPlayer: getMetadata

当页面加载时,我想播放演讲:

代码语言:javascript
运行
复制
I/chromium: [INFO:CONSOLE(62)] "Voice support NOT ready", source: https://code.responsivevoice.org/responsivevoice.js (62)
I/chromium: [INFO:CONSOLE(62)] "Voice support NOT ready", source: https://code.responsivevoice.org/responsivevoice.js (62)
I/chromium: [INFO:CONSOLE(62)] "Voice support NOT ready", source: https://code.responsivevoice.org/responsivevoice.js (62)
I/chromium: [INFO:CONSOLE(62)] "Voice support NOT ready", source: https://code.responsivevoice.org/responsivevoice.js (62)
I/chromium: [INFO:CONSOLE(62)] "Voice support NOT ready", source: https://code.responsivevoice.org/responsivevoice.js (62)
I/chromium: [INFO:CONSOLE(63)] "RV: speechSynthesis present but no system voices found", source: https://code.responsivevoice.org/responsivevoice.js (63)
I/chromium: [INFO:CONSOLE(64)] "RV: Enabling fallback mode", source: https://code.responsivevoice.org/responsivevoice.js (64)
D/MediaResourceGetter: ethernet/wifi connection detected
D/MediaHTTPConnection: filterOutInternalHeaders: key=User-Agent, val= SonyD5803 Build/23.4.A.1.232 stagefright/1.2 (Linux;Android 5.1.1)
D/MediaHTTPConnection: proxy null port 0
D/MediaResourceGetter: resource doesn't have video
D/MediaResourceGetter: extracted valid metadata: MediaMetadata[durationInMilliseconds=0, width=0, height=0, success=true]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-26 15:53:01

ResponsiveVoice说:

在iOS上,一些事件,如语音合成,需要从用户操作(即单击)中触发。例如,这会导致ResponsiveVoice语音调用无法在页面加载时工作。

对于语音合成,用户触发的动作只需进行一次。第一次之后的进一步直接呼叫将如预期的那样工作。

因此,推荐的最佳做法是在体验中添加一个“开始”按钮,供用户单击,并将其用作对responsiveVoice.speak()的初始化调用。如果需要的话,该调用可以有一个空白作为文本,因此不会对用户产生影响。

我认为android是一样的,但是我找到了解决我的问题的方法:

首先,我将加载包含文本到语音的javascript函数的html页面。然后像下面的代码那样加载函数本身:

代码语言:javascript
运行
复制
final Handler handler=new Handler();
handler.postDelayed(new Runnable() {

                        public void run() {
                            WebView webView = (WebView) findViewById(R.id.myWebview);
                            webView.loadUrl("javascript:speak('" + s + "');");

                        }
                    }, 5000 );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44090224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档