Reads Text Aloud (Ignores LaTeX Tags/Comments) - Give it a Try!
About: Simple web-based helper tool for proof reading LaTeX text, read the text out using the browser built in 'text-to-speech' synthesizer while ignoring LaTeX specific tags and comments.
How to use: Type the text you want read aloud (or copy and paste from your LaTeX document) into the textarea above, then click 'read'. Tags and comments, such as \cite{..} will automatically be ignored and not read out.
Very useful if you work with LaTeX documents reguarly - which can contain a mixture of tags - reads the text (skips tags).
Source Code (Vanila Javascript/HTML)
The implementation source code is very simple, and is include below for educational purposes. The reason the code is so simple is it builds on the browser's builtin speech API. (e.g.,
speechSynthesis
).
<div style='height:100px;width:100%;'>
Reads Text Aloud (Ignores LaTeX Tags/Comments) <br><br>
<textarea id='text' style='width:100%;height:80%;min-height:400px;'> Type text to read here ...
\section{Example} In the year 1902 John Smith [2,4] invented time travel \cite{citation} on a theoretical level, yet the [2] concepts % ignore this text %ignore this line are still used today.
</textarea>
<div> <br> About: Simple web-based helper tool for proof reading LaTeX text, read the text out using the browser built in 'text-to-speech' synthesizer while ignoring LaTeX specific tags and comments.<br><br> How to use: Type the text you want read aloud (or copy and paste from your LaTeX document) into the textarea above, then click 'read'. Tags and comments, such as \cite{..} will automatically be ignored and not read out. </div> <br>
<script> function readx() { let tb = document.getElementById('text'); let txt = tb.value;
var tts = {}; tts.Synth = window.speechSynthesis; tts.Voices = []; tts.Voices = tts.Synth.getVoices(); // get a list of available voices. tts.DvIndex = 0; //Used to help identify the default tts voice for Chrome or FF on the users platform. tts.DvRate = 0.85; // used to set speech rate between 0 and 2, 1 = 'normal'- there are other seemingly optional parameters like pitch, language, volume. tts.On = false; //Set to false to prevent tts production.
function ReadText(txt){
tts.Synth.cancel(); // Use tts to read text. A new speech synthesis utterance instance is required for each tts output for FF. // Chrome lets you redefine the SpeechSynthesizerUtterance.txt property- // as needed without having to create a new object every time you want speech. let ttsSpeechChunk = new SpeechSynthesisUtterance(txt); ttsSpeechChunk.voice = tts.Voices[tts.DvIndex]; //use default voice -- some voice must be assigned for FF to work. ttsSpeechChunk.rate = tts.DvRate; tts.Synth.speak(ttsSpeechChunk);
// if ( last ) //ttsSpeechChunk.onend = function(e){ //console.log('finished'); // Reveal.next(); //console.log( e ); // }
};
const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); var selectvoice = ""; if ( urlParams.has('voice') ) { selectvoice = urlParams.get('voice') }
// fix to get the default voice setTimeout(function(){ tts.Voices = tts.Synth.getVoices(); console.log('Available voices:') for (var ix = 0; ix < tts.Voices.length; ix++) { let voice = tts.Voices[ix]; console.log( ' voice:[' + voice.name + ']' );
if ( voice.default ) { tts.DvIndex = ix; console.log( '>>> default voice: ' + voice.name ); } // *** hack - force voice *** if ( voice.name == 'Google UK English Female' ) { tts.DvIndex = ix; }