Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change speaking immediately #7

Closed
HazardCreative opened this issue Dec 6, 2018 · 7 comments
Closed

Change speaking immediately #7

HazardCreative opened this issue Dec 6, 2018 · 7 comments

Comments

@HazardCreative
Copy link

The voice won't stop speaking the current section if something else is told to start. I need to have the option to switch right away and force something else to speak. I tried writing a function this way:

$().articulate('stop');
$(obj).articulate('speak');

...but it only starts speaking if the browser wasn't already speaking. Is there another way to accomplish this?

@acoti
Copy link
Owner

acoti commented Dec 6, 2018

I'm not actively supporting this anymore, but it does seem like you have the proper approach. In my demos, stopping an existing voice and playing a new one is not an issue, but that's based on a person clicking a button and pressing another one. There's a natural delay between the two voices.

So I wonder if the browser needs some sort of pause in there, so it can kind of reset itself, Maybe set a window.timeout of 500ms before starting the new voice?

@HazardCreative
Copy link
Author

HazardCreative commented Dec 7, 2018 via email

@acoti
Copy link
Owner

acoti commented Dec 8, 2018

At this point, you may be bumping up against browser limitations on how they implement speech synthesis. If I think of some other approach you can try, I'll let you know. Please keep me posted on how your testing proceeds.

@HazardCreative
Copy link
Author

Thanks for your help. I think it is browser limitations as well, because different browsers on different devices gave slightly different results. I wasn't able to resolve this for very short duration speech as in my use case.

As a workaround, I switched to playing an audio file to mark the final seconds. The audio file will play in parallel with speech synthesis if needed.

@sullyj3
Copy link

sullyj3 commented Jan 29, 2019

I ran into the same issue, it definitely seems to be a problem with the speechSynthesis api. A minimal self contained example is the following:

<html>
	<body>
		<div><button onclick="playFirst()">Play First</button></div>
		<div><button onclick="playSecond()">Play Second</button></div>

		<script type="text/javascript">
			const myText = "the first text";
			const myText2 = "the second text!";

			function playFirst() {
				speechSynthesis.speak(new SpeechSynthesisUtterance(myText));
			}

			function playSecond() {
				speechSynthesis.cancel();
				speechSynthesis.speak(new SpeechSynthesisUtterance(myText2));
			}
		</script>
	</body>
</html>

If you click the first button, then the second whilst the text from the first is still being spoken, the speech stops, and the second string is not spoken.

@sullyj3
Copy link

sullyj3 commented Jan 29, 2019

Hmm, it seems like the above snippet works in firefox, but not chrome.

@acoti
Copy link
Owner

acoti commented Jan 31, 2019

One thing I want to point out: there is a Chrome fix at lines 66-69 in the annotated "articulate.js" file. This was necessary at the time when the speech synthesis API was relatively new, but is also two years old. Perhaps this "fix" is no longer needed or is, somehow, affecting what you are trying to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants