Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speech gets cut off in firefox when page is auto-refreshed but not in google chrome

I have this problem where in firefox the speech gets cut off if the page is auto-refreshed, but in google chrome it finishes saying the speech even if the page is auto-refreshed. How do I fix it so that the speech doesn't get cut off in firefox even when the page is auto-refreshed?

msg = new SpeechSynthesisUtterance("please finish saying this entire sentence.");
window.speechSynthesis.speak(msg);

(function ($) {
  'use strict';
  if (window == window.top) {
    var body = $('body').empty();
    var myframe = $('<iframe>')
      .attr({ src: location.href })
      .css({ height: '95vh', width: '100%' })
      .appendTo(body)
      .on('load', function () {
        var interval;
        interval = 750; 
        setTimeout(function () {
          myframe.attr({ src: location.href });
        }, interval);
      });
  }
})(jQuery);
like image 466
frosty Avatar asked Jan 23 '19 13:01

frosty


People also ask

How do I enable speech synthesis in Chrome?

Click on the icon on the left of the URL bar, and open Site settings. Change the Sound setting from "Automatic (default)" to "Allow"

How do I refresh JavaScript in Firefox?

I use Ctrl + F5 . It's like a force refresh. This refreshes the page including re-downloading any referenced JavaScript files or CSS files even if they were cached. It will NOT clear anything else such as your browsing history.

How to fully reload page?

Hold down Ctrl and click the Reload button. Or Hold down Ctrl and press F5.

How to force to refresh a site?

Ctrl + F5 is the shortcut to trigger a refresh, which will force the page to reload. To make the browser refresh without relying on the cache, use Shift + Ctrl + F5. This triggers a “hard refresh”, so the browser pulls up the newest version of a web page.


1 Answers

I have this problem where in firefox the speech gets cut off if the page is auto-refreshed, but in google chrome it finishes saying the speech even if the page is auto-refreshed.

The described behaviour for Firefox is a sane expected implementation.

Browsing the source code of Firefox and Chromium the implementation of speechSynthesis.speak() is based on a socket connection with the local speech server. That server at *nix is usually speech-dispatcher or speechd (speech-dispatcher). See How to programmatically send a unix socket command to a system server autospawned by browser or convert JavaScript to C++ souce code for Chromium? for description of trying to implement SSML parsing at Chromium.

Eventually decided to write own code to achieve that requirement using JavaScript according to the W3C specification SpeechSynthesisSSMLParser after asking more than one question at SE sites, filing issues and bugs and posting on W3C mailings lists without any evidence that SSML parsing would ever be included as part of the Web Speech API.

Once that connection is initiated a queue is created for calls to .speak(). Even when the connection is closed Task Manager might still show the active process registered by the service.

The process at Chromium/Chrome is not without bugs, the closest that have filed to what is being described at the question is

  • Issue 797624: "speak speak slash" is audio output of .speak() following two calls to .speak(), .pause() and .resume()

  • Why hasn't Issue 88072 and Issue 795371 been answered? Are Internals>SpeechSynthesis and Blink>Speech dead? (for possible reason why "but in google chrome it finishes saying the speech even if the page is auto-refreshed." is still possible at Chrome)

.volume property issues

  • Issue 797512: Setting SpeechSynthesisUtterance.volume does not change volume of audio output of speechSynthesis.speak() (Chromium/Chrome)

  • Bug 1426978 Setting SpeechSynthesisUtterance.volume does not change volume of audio output of speechSynthesis.speak() (Firefox)

The most egregious issue being Chromium/Chrome webkitSpeechReconition implementation which records the users' audio and posts that audio data to a remote service, where a transcript is returned to the browser - without explicitly notifying the user that is taking place, marked WONT FIX

  • Issue 816095: Does webkitSpeechRecognition send recorded audio to a remote web service by default?

Relevant W3C Speech API issues at GitHub

  • The UA should be able to disallow speak() from autoplaying #27

  • Precisely define when speak() should fail due to autoplay rules #35 (ironically, relevant to the reported behaviour at Chromium/Chrome and output described at this question, see Web Audio, Autoplay Policy and Games and Autoplay Policy Changes)

    • Intent to Deprecate: speechSynthesis.speak without user activation

      Summary

      The SpeechSynthesis API is actively being abused on the web. We don’t have hard data on abuse, but since other autoplay avenues are starting to be closed, abuse is anecdotally moving to the Web Speech API, which doesn't follow autoplay rules.

      After deprecation, the plan is to cause speechSynthesis.speak to immediately fire an error if specific autoplay rules are not satisfied. This will align it with other audio APIs in Chrome.

  • Timing of SpeechSynthesis state changes not defined #39

  • Timing of SpeechSynthesisUtterance events firing not defined #40

  • Clarify what happens if two windows try to speak #47


In summary, would not describe the behaviour at Firefox as a "problem", but the behaviour at Chrome as being a potential "problem".

Diving in to W3C Web Speech API implementation at browsers is not a trivial task. For several reasons. Including the apparent focus, or available option of, commercial TTS/SST services and proprietary, closed-source implementations of speech synthesis and speech recognition in "smart phones"; in lieu of fixing the various issues with the actual deployment of the W3C Web Speech API at modern browsers.

The maintainers of speechd (speech-dispatcher) are very helpful with regards to the server side (local speech-dispatcher socket).

Cannot speak for Firefox maintainers. Would estimate it is unlikely that if a bug is filed relevant to the feature request of continuing execution of audio output by .speak() from reloaded window is consistent with recent autoplay policies implemented by browsers. Though you can still file a Firefox bug to ask if audio output (from any API or interface) is expected to continue during reload of the current window; and if there are any preferences or policies which can be set to override the described behaviour, as suggested at the answer by @zip. And get the answer from the implementers themselves.

There are individuals and groups that compose FOSS code which are active in the domain and willing to help SST/TTS development, many of which are active at GitHub, which is another option to ask questions about how to implement what you are trying to achieve specifically at Firefox browser.

Outside of asking implementers for the feature request, you can read the source code and try create one or more workarounds. Alternatives include using meSpeak.js, though that still does not necessarily address if Firefox is intentionally blocking audio output during reload of the window.

like image 77
guest271314 Avatar answered Oct 19 '22 23:10

guest271314