Ive found that inserting synthetic pauses using commas is very useful (like creating other manipulations). Here are some excerpts:
var speech = new SpeechSynthesisUtterance(), $content = document.querySelector('main').cloneNode(true), $space = $content.querySelectorAll('pre'), $pause_before = $content.querySelectorAll('h2, h3, h4, h5, h6, p, li, dt, blockquote, pre, figure, footer'), $skip = $content.querySelectorAll('aside, .dont_read'); // Don't read $skip.forEach(function( $el ){ $el.innerHTML = ''; }); // spacing out content $space.forEach(function($el){ $el.innerHTML = ' ' + $el.innerHTML.replace(/[\r\n\t]/g, ' ') + ' '; }); // Synthetic Pauses $pause_before.forEach(function( $el ){ $el.innerHTML = ' , ' + $el.innerHTML; }); speech.text = $content.textContent;
The key is to first clone the contents of the node so that you can work with it in memory, rather than manipulate the actual content. It seems to me that this works very well for me, and I can control it in JavaScript code, and not modify the source text.
source share