Skip to main content
  1. Home
  2. Knowledge Base
  3. eLearning Magic Toolkit - ElevenLabs Integration for Storyline
  4. Tips For Generating A Conversation (Multiple Concurrent ElevenLabs Audio Generations)

Tips For Generating A Conversation (Multiple Concurrent ElevenLabs Audio Generations)

Tips For Generating A Conversation (Multiple Concurrent ElevenLabs Audio Generations)

We have experimented with the ElevenLabs API in Articulate Storyline for some time and have tested what is the most efficient method for generating a full conversation between two characters using multiple chained requests to the ElevenLabs API occurring at the same time.

With the eLearning Magic Toolkit and Articulate Storyline, you can effectively execute as many ElevenLabs API audio generation scripts as you wish within the same project, however what we have found is that the ElevenLabs system tends to have a problem when more than 2 generations have been requested by the same account at the same time.

It is therefore the best approach to instead chain your requests in a sequence of two jobs running concurrently until all audio generations have completed.

So for example, if you intend to generate six separate audio tracks in total then you could set up a chain of events whereby audio tracks 1, 3 and 5 are completed one after another in sequence, whilst at the same time audio tracks 2, 4 and 6 are completed one after another in a separate sequence.

Both sequences should end roughly at the same time, and you can use a variable tracking system in Storyline to confirm the moment when all audio tracks have been produced (and audio data has been stored into Storyline variables for use.)

Once You Have All Audio Tracks Data Stored To Storyline Variables, You Can Use A  JavaScript Trigger Like This To Play Each Generated Audio Track In A Sequence:

// Define all audio URLs
var audioUrls = [
        getVar("ConvoOneURL"),
        getVar("ConvoTwoURL"),
        getVar("ConvoThreeURL"),
        getVar("ConvoFourURL"),
        getVar("ConvoFiveURL")
];

var audios = audioUrls.map(url => new Audio(url));
var currentAudioIndex = 0;

// Function to play audio and set up event listeners
function playAudio(index) {
        if (index >= audios.length) return; // Stop if there are no more audios to play

        var audio = audios[index];
        audio.onplay = () => {
            setVar(`AudioState${index + 1}`, "Playing"); // Dynamically setting the variable name
        };
        audio.onended = () => {
            setVar(`AudioState${index + 1}`, "Stopped");
            setTimeout(() => {
                playAudio(index + 1); // Play the next audio after a 3-second delay
            }, 1700);
        };
   audio.play().catch(error => console.error(`An error occurred when trying to play audio ${index + 1}:`, error));
}

// Start playing the first audio
playAudio(currentAudioIndex);

The above examples assumed that we have stored all audio data generated by the ElevenLabs API process (see this page) have been placed into Storyline variables named ‘ConvoOneURL’, ‘ConvoTwoURL’, etc. etc.

With each of these values referenced within an array named audioUrls, we then cycle through and play each audio track one at a time through the rest of the script.

onplay and onended event listeners are used once again to check when playing and ended states have been reached with each audio, but as you can see we have used some clever manipulation of the script so that the Storyline variable associated with each audio track is updated one at a time. So for example, the use of AudioState${index + 1} will update the Storyline variable AudioState1 when the very first audio track is either playing or has ended.

The playAudio function is recalled as soon as each audio has ended, and through a setTimeout method we can create a small pause to be played between each audio track being played. Just update the 1700 value to a different number (in milliseconds) if you want to increase or decrease the pause length.

Take a look at our own Storyline demo which uses the eLearning Magic Toolkit and the method explained above to generate multiple audio tracks in sequence and play them one after another on the slide once generation has completed:

Read the rest of our Knowledge Base pages to make the most of eLearning Magic Toolkit.

Related Articles

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.