Using a speech engine to highlight words: Difference between revisions
(Added AutoHotkey example) |
m (Reword the task (based on comments in discussion page) to make it clearer what was intended) |
||
Line 1: | Line 1: | ||
{{draft task}}[[Category:Speech synthesis]][[Category:Temporal media]] |
{{draft task}}[[Category:Speech synthesis]][[Category:Temporal media]] |
||
Send a piece of text in a simple GUI through a text-to-speech engine (producing spoken output). At the same time as each word is being spoken, highlight the word in the GUI. (The GUI does not need to be interactive, but some extra kudos for allowing users of the code to provide their own text.) |
|||
The task is to highlight and speak each word as it is spoken by the speech engine. |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
We use the simple SAPI.SPVoice COM Object and a parsing loop. |
We use the simple SAPI.SPVoice COM Object and a parsing loop. |
Revision as of 11:02, 11 September 2011
Send a piece of text in a simple GUI through a text-to-speech engine (producing spoken output). At the same time as each word is being spoken, highlight the word in the GUI. (The GUI does not need to be interactive, but some extra kudos for allowing users of the code to provide their own text.)
AutoHotkey
We use the simple SAPI.SPVoice COM Object and a parsing loop. The highlighting is done with EM_SETSEL and Notepad. Rather crude, but it works. Due to the simplistic nature of the parsing loop, the text ends with a space. <lang AutoHotkey>SetTitleMatchMode 2 EM_SETSEL := 0x00B1
Run notepad,,,pid WinWaitActive ahk_pid %pid% ControlSetText, Edit1, % text := "AutoHotkey was the first to implement this task! ", ahk_pid %pid%
pVoice := ComObjCreate("Sapi.spvoice"), i := 1 ; the spvoice COM Object ships with the OS
- parse the text
While lf := SubStr(text, i, 1) {
If lf = %A_Space% { SendMessage, EM_SetSel, % i-StrLen(word)-1, % i-1, Edit1, ahk_pid %pid% pVoice.speak(word), word := "", i++ } Else word .= lf, i++
}</lang>