File: outloud

package info (click to toggle)
emacspeak 24-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,092 kB
  • ctags: 4,597
  • sloc: xml: 54,699; lisp: 42,103; tcl: 1,799; makefile: 810; cpp: 603; sh: 566; ansic: 153; perl: 124
file content (380 lines) | stat: -rwxr-xr-x 8,715 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/usr/bin/tcl
# Keywords: Emacspeak, ViaVoice Outloud , TCL
# {{{ LCD Entry: 

# LCD Archive Entry:
# emacspeak| T. V. Raman |raman@cs.cornell.edu
# A speech interface to Emacs |
# $Date: 2006/05/03 02:54:04 $ |
#  $Revision: 24.0 $ | 
# Location undetermined
#

# }}}
# {{{ Copyright:  
#Copyright (C) 1995 -- 2001, T. V. Raman 
#All Rights Reserved
#
# This file is not part of GNU Emacs, but the same permissions apply.
#
# GNU Emacs is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# }}}
# {{{source common code 

set wd [file dirname $argv0]
source $wd/tts-lib.tcl

# }}}
# {{{ procedures  

proc version {} {
    q " ViaVoice [ttsVersion]"
    d
}

proc tts_set_punctuations {mode} {
    global tts
    set tts(punctuations) $mode
    service
    return ""
}

proc tts_set_speech_rate {rate} {
    global tts
    set factor $tts(char_factor) 
    set tts(speech_rate) $rate
    say "`vs$rate "
    service
    return ""
}

proc tts_set_character_scale {factor} {
    global tts
    set tts(say_rate) [round \
                           [expr $tts(speech_rate) * $factor ]]
    set tts(char_factor) $factor
    service
    return ""
}

proc tts_say {text} {
    global    tts
    service 
    set r $tts(speech_rate)
    set prefix "`v1 `vs$r "
    regsub -all {\[\*\]} $text { `p1 } text 
    synth " $prefix $text"
    service
    closeDSP
    return ""
}

#formerly called tts_letter

proc l {text} {
    global tts
    set r $tts(speech_rate)
    set prefix "`v1 `vs$r "
    if {[regexp  {[A-Z]} $text]} {
        set prefix "$prefix `vb80"
    }
    set tts(not_stopped) 1
    synth "$prefix  `ts2 $text `ts0"
    service
    closeDSP
    return ""
}

#formerly called tts_speak
proc d {} {
    service
    speech_task
}

proc tts_resume  {} {
    resume
    return ""
}
proc tts_pause {} {
    pause
    return ""
}

#formerly called tts_stop 

proc s {} {
    global tts
    if {$tts(not_stopped) == 1} {
        set tts(not_stopped) 0
        stop
        queue_clear
    } else {
        puts stderr StopNoOp
    }
}

#formerly called tts_tone
#produce tones via midi 

proc t  {{pitch 440} {duration 50}} {
    global tts queue
    if {$tts(midi)} {
        set inst 9
        set len .1
        set note [expr $pitch / 10]
        n $inst $note $len
        return ""
    }
    if {$tts(beep)} {
        b $pitch $duration
        return ""
    }
    service
}

proc sh  {{duration 50}} {
    global tts queue 
    set silence "`p$duration "
    set queue($tts(q_tail)) [list t $silence]
    incr tts(q_tail)
    service
    return ""
}


proc tts_split_caps {flag} {
    global tts 
    set tts(split_caps) $flag
    service
    return ""
}

proc tts_capitalize {flag} {
    global tts 
    set tts(capitalize) $flag
    service
    return ""
}

proc tts_allcaps_beep {flag} {
    global tts 
    set tts(allcaps_beep) $flag
    service
    return ""
}

proc tts_reset {} {
    global tts 
    synth  -reset
    queue_clear
    synth "Resetting engine to factory defaults."
}

proc r {rate} {
    global queue  tts
    set queue($tts(q_tail)) [list s  "`vs $rate "]
    incr tts(q_tail)
    return ""
}

proc useStereoOutput {} {
    global tts
    setOutput buffer
}

# }}}
# {{{ speech task 

proc trackIndex {index} {
    global tts
    set tts(last_index) $index
}

proc service {} {
    global tts
    set talking [speakingP]
    while {$talking == 1} {
        set status   [lsearch [select [list  stdin]  {} {} 0.02] stdin]
        if { $status >= 0} {
            set tts(talking?) 0
            set talking 0
            break
        } else {
            set talking [speakingP]
        }
    }
    return $talking
}

proc speech_task {} {
    global queue tts
    set tts(talking?) 1
    set tts(not_stopped) 1
    set r $tts(speech_rate)
    set length [queue_length]
    set prefix "`v1 `vs$r "
    loop index 0 $length {
        set event   [queue_remove]
        set event_type [lindex $event 0]
        switch  -exact -- $event_type {
            s {
                set text [clean [lindex $event 1]]
                synth "$prefix $text"
                set retval [service]
            }
            a {
                set sound [lindex $event 1]
                exec $tts(play) $sound >/dev/null   &
            }
            b {
                if {$tts(beep)} {
                    lvarpop event 
                    eval beep $event
                }
            }
            n {
                if {$tts(midi)} {
                    lvarpop event 
                    eval note $event
                }
            }
        }
        if {$tts(talking?) == 0} {break;} 
    }
    set tts(talking?) 0
    service
    if {$tts(talking?) == 0} {closeDSP} 
    return ""
}

# }}}
# {{{clean 

#preprocess element before sending it out:

proc clean {element} {
    global queue tts 
    if {[string match all $tts(punctuations)] } {
        regsub -all --  {\*} $element \
            { `00 star } element
        regsub -all --  {-} $element \
            { `00 dash } element
        regsub -all --  {;} $element \
            { `00 semicolen } element
        regsub -all --  {\(} $element \
            { `00 left `00 paren } element
        regsub -all --  {\)} $element \
            { `00 right `00 paren } element
        regsub -all --  {@} $element \
            { `00 at } element
        regsub -all  {[.,!?;:+=/'\"@$%&_*()]} $element  \
            { `00 \0 `p10 }   element
    } else {
        regsub -all  {[*%&()\"]} $element  {}   element
        regsub -all {([0-9a-zA-Z])([@!;/:()=\#,.\"])+([0-9a-zA-Z])} $element \
            {\1 `p5 \3} element
        regsub -all {``} $element { `ar } element
        regsub -all {''} $element { `af} element
        regsub -all {' }  $element { `p1  } element
        regsub -all --  {--} $element { `p10  } element
        regsub -all -- {-}  $element { `p1   } element 
    }
    if {$tts(capitalize) } {
        regsub -all {[A-Z]} $element {`ar`p10   & } element
    }
    if {$tts(split_caps) } {
        if  {$tts(allcaps_beep)} {
            set tone ""
            set abbrev_tone ""
        } else {
            set tone ""
            set abbrev_tone ""
        }
        set allcaps [regexp {[^a-zA-Z0-9]?([A-Z][A-Z0-9]+)[^a-zA-Z0-9]} $element full  match ]
        while {$allcaps } {
            if {[string length $match] <=3} {
                set abbrev " $abbrev_tone$match"
                regsub -all {[A-Z]} $abbrev {& `p1 } abbrev
                regsub -all A $abbrev {[ey]} abbrev 
                regsub $match $element  $abbrev element
            } else {
                regsub $match $element "$tone[string tolower $match]"  element
            }
            set allcaps [regexp {[^a-zA-Z0-9]([A-Z][A-Z0-9]+)[^a-zA-Z0-9]} $element full  match ]
        }
        regsub -all {[A-Z]} $element { `p1 &} element
        regsub -all {([^ -_A-Z])([A-Z][a-zA-Z]* )} $element\
            {\1 `p1 \2 } element
        regsub -all {([^ -_A-Z])([A-Z])} $element\
            {\1 `p1 \2} element
    }
    return $element
}

# }}}
# {{{ Initialize and set state.

#do not die if you see a control-c
signal ignore {sigint}

#initialize outloud 
tts_initialize
set tts(speech_rate)  75
notes_initialize
beep_initialize
set tts(input) file0
if {[info exists server_p]} {
    set tts(input) sock0
}
set servers [file dirname $argv0]
set tclTTS $servers/linux-outloud
#set ECIINI unless already set
if {![info exists env(ECIINI)] || ![file exists $env(ECIINI)] } {
    set env(ECIINI) $tclTTS/eci.ini
}
#conditionally use alsa if available
if {[file exists /usr/include/alsa/asoundlib.h]
    && [file exists  $tclTTS/atcleci.so]} {
    load $tclTTS/atcleci.so
    proc closeDSP {} {
        #stubbed out 
    }
    set tts(play) /usr/bin/aplay
    synth {`v1 Via Voice using Alsa.}
} else {
    load $tclTTS/tcleci.so
    set tts(stereo) 1
    useStereoOutput
    synth {`v1 Via Voice.}
}

service

#Start the main command loop:

commandloop 


# }}}
# {{{ Emacs local variables  

### Local variables:
### major-mode: tcl-mode 
### voice-lock-mode: t
### folded-file: t
### End:

# }}}