Forum Discussion
Targeting Text to Speech (TTS) with JavaScript
For those that may be looking in the future, a colleague helped out with this and changed my perspective completely. Instead of attempting to pause/play, he uses "mute" and targets the audio. With a combination of a check mark updating a variable that goes to an Execute Javascript, I was able to allow users to mute the audio through the entire project.
The check mark is on the first slide and sets the variable "autoplay" to "off" if selected. Then, the Execute Javascript on the page will mute the audio if autoplay = off using the following code:
"var player = GetPlayer();
var autostart = player.GetVar("autoplay");
var appState = window.DS ? DS.appState : require("helpers/appState");
var currentVol = appState.currentVolume(); // 0 = muted, 1 = full volume
if (autostart === "off") {
// Force mute if not already muted
if (currentVol !== 0) {
appState.onToggleVolume();
}
window.startAudioOff = true;
} else if (autostart === "on") {
// Restore to full volume if muted
if (currentVol === 0) {
appState.onToggleVolume();
}
window.startAudioOff = false;
}"
I added this to the top level Master slide so that it "trickles down" the heirarchy and so I don't have to add it to every slide manually.