KB116: Overcoming the 256 character dynamicPlay() limit

As described in KB112, the limit for the dynamicPlay 'say' parameter is 256 characters. You can go beyond this limit by calling dynamicPlay multiple times, typically with one sentence per call, in rapid succession. The first play will begin as soon as it is received, and each subsequent one is started in turn as the preceding one completes.

If you have a paragraph of text, you can use the following function to break it down into an array of sentences:

function sentenceSplit(s) {
    let a = (s + " ").replace(/([\.!\?]+[ ]+)/g, "$1\n").split("\n");
    a = a.map(s => s.trim()).filter(s => s.length > 0);
    return a;
}

You can then use this code to play an arbitrarily long span of text.

function playUnlimited(text) {
    for (let s of sentenceSplit(text)) {
        myAgent.dynamicPlay({say: s});
    }
}

This approach has several advantages. Since the first play only involves one sentence, it can get started rapidly. Then, while the first sentence is speaking, a feature called "preloading" ensures that the next sentence is preloaded by the Agent module, so that it is ready to go with minimal delay as soon as the first one ends. If you invoke msAgent.stop() at any time, then the presentation smoothly ends, and the remainder of the queue is flushed.





Copyright © 2025 Media Semantics, Inc. All rights reserved.
Comments? Write webmaster@mediasemantics.com.
See our privacy policy.