-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmic2driver.spin
More file actions
234 lines (160 loc) · 25.5 KB
/
Copy pathEmic2driver.spin
File metadata and controls
234 lines (160 loc) · 25.5 KB
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
{{ Emic2driver
Erlend Fj. 2016
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Provides high level routines for driving the TTS chip Emic2
Does not support RX i.e. will not read Emic replies, so calling routine has to insert pauses before next speak.
A simple demo is embedded in the object, and that section can be commented out if memory space is precious.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
}}
{
Acknowledgements:
=======================================================================================================================================================================
About ' VOICES EPSON CODES
The Emic2 is a reasonable means to add speaking capabilities to projects. ' ============================= =============================
More professional TTS modules cost five times as much. ' 0: Perfect Paul (Paulo) \/ Decrease pitch
Simple TTS can be achieved by using the Epson codes, but if more advanced ' 1: Huge Harry (Francisco)
intonation is required, DECtalk codes are better. ' 2: Beautiful Betty /\ Increase pitch
' 3: Uppity Ursula
' 4: Doctor Dennis (Enrique) >> Increase speaking rate
' 5: Kit the Kid
' 6: Frail Frank << Decrease speaking rate
' 7: Rough Rita
' 8: Whispering Wendy (Beatriz) __ Emphasize the next word
'
## Whisper the next word
REF: ' SPECIAL CHARACTER ENTRY:
http://www.grandideastudio.com/emic-2-text-to-speech-module/ ' use "\x plus hex format char :-) Select voice
=======================================================================================================================================================================
}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 'use 5MHz crystal
clk_freq = (_clkmode >> 6) * _xinfreq 'system freq as a constant
mSec = clk_freq / 1_000 'ticks in 1ms
uSec = clk_freq / 1_000_000 'ticks in 1us (80 ticks)
bitDur = clk_freq / 9600 'serial comms bit duration at 9600b/s
VAR
BYTE Sentence[128] 'To hold the text to be sent to Emic2
BYTE NewSentence[128]
OBJ
pst : "Parallax Serial Terminal"
PUB Main | ttsPIN, value, person, speed, loudness, pause 'Demo code (comment out if the space is needed)
pst.Start(9600) 'Remember to start the terminal at 9600b/s
WAITCNT(3*clkfreq + cnt)
ttsPIN:= 16 '<= set pin number for demo here!
Default(ttsPIN)
BYTEMOVE(@Sentence, @DefaultSentence, StrSize(@DefaultSentence)) 'Copy default content into sentence
pst.Str(String("Test of Emic2 - press Enter"))
value := pst.DecIn
pst.Chars(pst#NL, 2)
pst.Chars(pst#NL, 2)
REPEAT
pst.Str(@Sentence)
pst.Chars(pst#NL, 2)
pst.StrInMax(@NewSentence, 128)
IF StrSize(@NewSentence)> 1
BYTEMOVE(@Sentence, @NewSentence, StrSize(@NewSentence))
BYTE[@Sentence][StrSize(@NewSentence)]:= 0
' pst.Str(@Sentence)
pst.Chars(pst#NL, 2)
pst.Str(String("Choose voice (0 - 8) "))
person := 0 #> pst.DecIn <# 9
Voice(person, ttsPIN)
pst.Chars(pst#NL, 2)
pst.Str(String("Choose rate (75 - 600) "))
speed := 75 #> pst.DecIn <# 600
Rate(speed, ttsPIN)
pst.Chars(pst#NL, 2)
pst.Str(String("Choose volume ( -48 - 18) "))
loudness := -48 #> pst.DecIn <# 18
Volume(loudness, ttsPIN)
pst.Chars(pst#NL, 2)
pause:= Speak(@Sentence, ttsPIN)
WAITCNT((pause*clkfreq) + cnt)
pst.Chars(pst#NL, 2)
pst.Str(String("-again-"))
pst.Chars(pst#NL, 2)
PRI RandomPick(range) | rnd
rnd := cnt?
rnd := || rnd
rnd := rnd/(2147483647/range)
RETURN rnd
DAT
DefaultSentence BYTE "__Hello world, let us talk.",0
'Application level functions
'=========================================================
PUB Speak(ptrText, PINtts)
TxB(83, PINtts) '"S" initiates tts
TxStr(ptrText, PINtts) 'Transmit text string
TxB(10, PINtts) 'and finish with a CR
RETURN STRSIZE(ptrText)/10 'char count can be used to guesstimate wait delay
PUB Stop(PINtts)
TxB(88, PINtts) '"X" to stop
PUB PausePlay(PINtts)
TxB(90, PINtts) '"Z" to Pause, next time to play
PUB Voice(parVoice, PINtts) '0 to 8
TxB(78, PINtts) '"N" to select voice
TxB(parVoice + 48, PINtts) 'add 48 to convert voice to ASCII number
TxB(10, PINtts)
PUB Volume(parVolume, PINtts) | vol '-48 to 18
vol:= parVolume
TxB(86, PINtts) '"V" to select volume
IF vol < 0
TxB(45,PINtts)
vol:= ||vol
TxB( (vol / 10) + 48, PINtts )
vol:= vol - 10*(vol / 10)
TxB( vol + 48, PINtts)
TxB(10, PINtts)
PUB Rate(parRate, PINtts) | rte '75 to 600
rte:= parRate
TxB(87, PINtts) '"W" to select rate
TxB((rte / 100) + 48, PINtts)
rte/= 10
TxB((rte / 10) + 48, PINtts)
rte/= 10
TxB(rte + 48, PINtts)
TxB(10, PINtts)
PUB Language(parLanguage, PINtts) '0 to 2
TxB(76, PINtts) '"L" to select language
TxB(parLanguage + 48, PINtts) 'add 48 to convert language to ASCII number
TxB(10, PINtts)
PUB Parser(parParser, PINtts) '0=DECtalk, 1=Epson
TxB(80, PINtts) '"N" to select parser
TxB(parParser + 48, PINtts) 'add 48 to convert parser to ASCII number
TxB(10, PINtts)
PUB Default(PINtts)
TxB(82, PINtts) '"R" to revert to default settings
TxB(10, PINtts)
'Low level functions
'=========================================================
PRI TxStr(strAddr,txPin)
REPEAT STRSIZE(strAddr) 'for each character in string
TxB(BYTE[strAddr++],txPin) 'write the character
PRI TxB(txByte,txPin) | t
txByte := (txByte | $100) << 1 'add start bit, and OR in a stop bit
OUTA[txPin] := 1 'idle state
DIRA[txPin]~~
t := CNT 'sync
REPEAT 10 'start + eight data bits + stop
WAITCNT(t += bitDur) 'wait bit duration, first wait keeps 'idle state' for one bit duration
OUTA[txPin] := txByte 'output lsb,
txByte >>= 1 'then shift right to move next bit in place for tx
DAT
{{
Terms of Use: MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}}