Using a speech engine to highlight words: Difference between revisions

→‎{{header|REXX}}: added the REXX computer programming language.
m (added whitespace before the TOC (table of contents) and in the task's preamble, and added a ;Related (Rosetta Code) task.)
(→‎{{header|REXX}}: added the REXX computer programming language.)
Line 126:
While[i < Length@words, i++; FinishDynamic[]; Speak[words[[i]]];
Pause[Max[0.7, 0.12 StringLength[words[[i]]]]]]; i = 0]}]</lang>
 
=={{header|REXX}}==
{{works with|Windowx/XP or later}}
Programming note: &nbsp; This REXX program uses a freeware program &nbsp; NIRCMD &nbsp; to interface with the Microsoft Windows speech synthesizer program &nbsp; '''SAM''', &nbsp; a text to speech using a male voice. &nbsp; SAM can possibly be configured to use other voices with later releases of Windows. &nbsp; More recent Microsoft Windows have another speech synthesizer program: &nbsp; ANNA.
 
Each word of the text is highlighted (by showing the word in uppercase). &nbsp; the terminal screen is cleared before showing the text that is being spoken; &nbsp; the repeated calls to the (Windows) speech engine makes for a slower speech rate.
<lang rexx>/*REXX program uses a command line interface to invoke Windows SAM for speech synthesis.*/
parse arg t /*get the (optional) text from the C.L.*/
#= words(t)
if #==0 then exit /*Nothing to say? Then exit program.*/
dq= '"' /*needed to enclose text in dbl quotes.*/
rate= 1 /*talk: -10 (slow) to 10 (fast). */
/* [↓] where the rubber meets the road*/
do j=1 for #
x= word(t, j); upper x /*extract 1 word, capitalize it for HL.*/
if j==1 then LHS= /*obtain text before the spoken word. */
else LHS= subword(t, 1, j-1)
if j==# then RHS= /*obtain text after the spoken word. */
else RHS= subword(t, j+1)
'CLS' /*use this command to clear the screen.*/
say 'speaking: ' space(LHS x RHS) /*show text, one word is capitalized. */
oneWord= dq x dq /*surround a word in double quotes (").*/
'NIRCMD' "speak text" oneWord rate /*NIRCMD invokes Microsoft's Sam voice*/
end /*j*/ /*stick a fork in it, we're all done. */</lang>
Note: &nbsp; The name of the above REXX program is &nbsp; '''SPEAKHI.REX'''<br>
'''usage''' &nbsp; using the command:
<pre>
speakhi This is an example of speech synthesis.
</pre>
 
=={{header|Ruby}}==