4

I've got a website (www.myexamplewebsite.com) that looks simplified like this:

<html>
<head>
</head>
<body>
  <img src="img/speaker-icon.png" onclick="speakerFunction()">
<script>
  function speakerFunction() {
     var text = new SpeechSynthesisUtterance("This is a test.");
     text.lang = 'en-US';
     window.speechSynthesis.speak(text);                                    
    }
</script>
</body>
</html>

And I have also a simple Android-application which is basically a webview that displays my website:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView myWebView = (WebView) findViewById(R.id.myWebView);
        myWebView.loadUrl("www.myexamplewebsite.com");
        myWebView.setWebViewClient(new MyWebViewClient());
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
    }

    // Use when the user clicks a link from a web page in the WebView
    private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (Uri.parse(url).getHost().equals("www.myexamplewebsite.com")) {
                return false;

            }

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    }
}

My problem is the following:

When I visit the example website in a normal browser (Chrome, Firefox) on my desktop-pc it works how it should work. If I click on the image on the website, I can hear the text "This is a test."

If I visit the example website with the Chrome-App for Android on my smartphone it works also. But if I visit the website with the Firefox-App or within my own App with the webview (see above) then it doesn't work.


Update 1: I specified the language explicitely and I tried it with the crosswalk framework but that also didn't solve the problem.

  • Possible duplicate of [SpeechSynthesisUtterance not working in mobile broswer](https://stackoverflow.com/questions/28806399/speechsynthesisutterance-not-working-in-mobile-broswer) – Nikolay Shmyrev Jan 04 '18 at 10:55
  • Also related https://stackoverflow.com/questions/44835303/select-language-for-text-to-speed-on-android-webview/44850887#44850887, it might help to specify the language explicitely – Nikolay Shmyrev Jan 04 '18 at 10:57

1 Answers1

0

SpeechSynthesisUtterance is not supported by android webview https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance

Although SpeechSynthesis is supported but since SpeechSynthesis work based on the SpeechSynthesisUtterance object passed into it, it won't all still work.

https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis

gentle
  • 15
  • 7