Forum Discussion

HoneyTurner's avatar
HoneyTurner
Community Member
6 months ago
Solved

Muting Audio in Timeline

I'm creating a slide that includes a Text 2 Speech introduction, theme music, then Text 2 Speech instructions. I would like to add a toggle to the page that will allow the user to mute the theme mu...
  • Nedim's avatar
    Nedim
    6 months ago

    There are multiple ways to detect an audio file name. For now, I’ll focus on one way.
    Execute the following JavaScript global function when the timeline starts on this slide:

    window.muteAudio = function(filename) {
        var audioElements = document.querySelectorAll('audio');
    
        audioElements.forEach(function(audio) {
            const audioFileName = audio.src.split('/').pop();  
            const audioFilePath = `story_content/${filename}`;
    
            if (audio.src.includes(audioFilePath)) {
                audio.muted = !audio.muted;
            }
        });
    };
    
    • Publish your file to Web.
    • Open the published folder and navigate to the story_content directory.
    • Copy and paste the exact filename of the audio file you want to control.

    Now, you can mute or unmute the specific audio file by executing JavaScript when the user clicks toggle button:

    muteAudio('your-audio-file.mp3');