0 votes
by (190 points)

So I've scoured the other asks for more information on this and came upon the gem that gave this code:

$(document).on(":passagerender", function (ev) {
	var synth = window.speechSynthesis;
	var utterThis = new SpeechSynthesisUtterance(Story.get(passage()).text);
	utterThis.voice = speechSynthesis.getVoices()[0];
	synth.speak(utterThis);
});

This code is great and does what I need but the issue that if I put this in the game then there's not the ability to toggle the voice (for those who don't want it). As well as the fact that the voice reads the code along with the passage text. 

So my questions are: Is there a way to stop it from reading the code (i.e. it reads the <<nobr>><<endnobr>>) or is that just something that's going to happen? And how would I go about toggling whether or not you want the voice to come up, I'm guessing a settings tab but I might be wrong. 

1 Answer

+1 vote
by (2.4k points)
I've never seen that code, but...

About how not to read the code itself, I supose the key would be changing the Story.get(passage()).text part for something that differentiates between readable and non-readable elements. Maybe adding a class="readable" tag to every text you want to read and using some function in that Story.get() to recover those tagged elements? (Sorry, I'm not sure right now how to do it, but I think I would do it like that)

And about how to toggle it on and off, I supose you could enclose synth.speak(utterThis) in an if code that checks if the player has selected it on the game Settings. But sorry again, I don't know how to use the Setting API (I'm sure you can do it, I think I've seen something similar done somewhere).
...