SpeakJet
SpeakJet.h
1// SpeakJet.h
2//
3// Author: Mike McCauley (mikem@airspayce.com)
4// Copyright (C) 2011 Mike McCauley
5// $Id: SpeakJet.h,v 1.3 2012/11/26 21:01:51 mikem Exp mikem $
6/// \mainpage SpeakJet library for Arduino
7///
8/// This is the Arduino SpeakJet library.
9/// It provides an object-oriented class for driving a SpeakJet
10/// http://www.sparkfun.com/datasheets/Components/General/speakjet-usermanual.pdf speech synthesizer chip,
11/// such as installed on SparkFun VoiceBox shield https://www.sparkfun.com/products/10661
12///
13/// It supports speaking of:
14/// - raw individual phonemes
15/// - arrays of phonemes
16/// - words from a custom dictionary or the standard built-in dictionary
17/// - sentences (sequences of words) from a custom dictionary or the standard built-in dicitonary
18/// - integers from 0 to over 4 billion
19/// - strings of digits or IP addresses
20/// - creation and conversion of custom word-to-phonemes dictionaries
21///
22/// The version of the package that this documentation refers to can be downloaded
23/// from http://www.airspayce.com/mikem/arduino/SpeakJet/SpeakJet-1.6.zip
24/// You can find the latest version at http://www.airspayce.com/mikem/arduino/SpeakJet
25///
26/// Tested with SparkFun VoiceBox on Uno, Duemilanove, Diecimila, Mega.
27/// Tested with Arduino 0021 and 1.0.2
28///
29/// \par Electrical connection to the SpeakJet
30///
31/// The connection to the SpeakJet chip requires 3 digital pins:
32/// - Serial Data Tx from Arduino to the SpeakJet (RS232, using the SoftwereSerial class)
33/// - Chip ready pin from the SpeakJet 'Speak' to the Arduino (low is ready)
34/// - Reset from the Arduino to the SpeakJet (high is reset)
35///
36/// Naturally, ground and 5V are also required to supply the chip.
37///
38/// The SpeakJet library uses SoftwareSerial to send Serial commands at 9600 baud to the SpeakJet chip, using any of the
39/// Arduino Digital output pins. The default is pin D2. No serial data is read from the SpeakJet chip.
40///
41/// The SpeakJet constructor is where you specify the Arduino digital pins to use for each of these functions.
42/// The default values work with a standard SparkFun VoideBox shield https://www.sparkfun.com/products/10661
43///
44/// \par Dictionaries
45///
46/// The SpeakJet library comes with a standard dictionary of approximately 1400 words, phrases and sound effects.
47/// The functions speakWord() and speakWords() speak sound effects and words from this dictionary. It is based on the
48/// PhraseALator.Dic dictionary file provided by SpeakJet, but converted to a 'C' structure
49/// for use by this SpeakJet library (see standardDict.cpp).
50///
51/// Alternatively you can create your own dictionary (either as a subset of the standard dictionary,
52/// or from scratch with your own words, or a combination of the two) and use speakWordfromDictionary()
53/// and speakWordsfromDictionary().
54///
55/// The included convertDict.pl perl script reads one or more dictionary files in the same format as
56/// PhraseALator.Dic and emits a 'C' file suitable for including in a header file or a .c or .cpp file.
57///
58/// Also included is a smaller dictionary (numericDict.cpp) that includes mostly only numbers, and is used to speak
59/// integers and digits with speakNumber() and speakDigits().
60///
61/// In SpeakJet, a Dictionary is an array of DictionaryItem structures, terminated by an empty DictionaryItem.
62/// You can build these by hand in your sketch, or you can rely on convertDict to create them from
63/// a text .dic file. In any case, it is essential that the Dictionary, and all the words and code sequences it
64/// points to are in PROGMEN. This will save you RAM.
65///
66/// The standard dictionary and it set of 1400 or so words occupies about 30kbytes of Flash program memory.
67/// This is far biger than some Arduinos can handle, and is quite close to the total permissable program size
68/// for say the Arduino Uno. Fortunately the standard dictionary is only linked if you use
69/// speakWord() or speakWords().
70///
71/// The supplied standard and numeric dicitonaries only support English, but you could contruct your own
72/// dictionaries to support other languages.
73///
74/// \par convertDict.pl
75///
76/// This support script is used to convert text dictionary files into 'C' structures suitable for including in
77/// sketches or other C program files. It is used to create the numericDict.cpp and standardDict.cpp header
78/// files that are shippped with the SpeakJet library, but you can use to to create your own dictionary header files.
79///
80/// Command line arguments can be used to control the C variable name of the dictionary,
81/// so you can have several different dictionaries in your sketch.
82/// It can be used to creat a single dictionary out of one or more dictionary text files.
83///
84/// Caution: while the .dic file format permits words to be defined in terms of other words, this is not supported
85/// by convertDict.pl. Any word defintion that is *not* in terms of basic phonemes is flagged as an error and
86/// is not added to the dictionary structure. This is mainly to avoid the fx* words int the PhraseALator.Dic file
87/// being included in the standard dictionary and blowing the size out to more that 32 k.
88///
89/// The format of the input dictionary files is:
90/// [words]
91/// word=\\PH \\PH \\PH \\PH ....
92/// where 'word' is the ASCII text of the word to be spoken, and \\PH \\PH ... is a sequence of standard phoneme
93/// mnemonics or control codes that will be used to speak the word.
94///
95/// convertDict.pl will automatically append the EndOfPhrase byte required by every DictionaryEntry code array.
96///
97/// \par Examples.
98///
99/// A number of example sketches and a test suite illustrating the use of the public functions in SpeakJet is included.
100///
101/// \par Installation
102///
103/// Install in the usual way: unzip the distribution zip file to the libraries
104/// sub-folder of your sketchbook.
105///
106/// This software is Copyright (C) 2011 Mike McCauley. Use is subject to license
107/// conditions. The main licensing options available are GPL V2 or Commercial:
108///
109/// \par Open Source Licensing GPL V2
110///
111/// This is the appropriate option if you want to share the source code of your
112/// application with everyone you distribute it to, and you also want to give them
113/// the right to share who uses it. If you wish to use this software under Open
114/// Source Licensing, you must contribute all your source code to the open source
115/// community in accordance with the GPL Version 2 when your application is
116/// distributed. See http://www.gnu.org/copyleft/gpl.html
117///
118/// \par Commercial Licensing
119///
120/// This is the appropriate option if you are creating proprietary applications
121/// and you are not prepared to distribute and share the source code of your
122/// application. Contact info@airspayce.com for details.
123///
124/// \par Revision History
125///
126/// \version 1.0 Initial release
127/// \version 1.1 Improve documentation
128/// \version 1.3 Now Compiles amd runs with Arduino 0021. Added more documentation.
129/// Constructor invertPin argument
130/// removed (not available before Arduino 1.0)
131/// \version 1.4 Updated author and distribution location details to airspayce.com
132/// \version 1.5 2024-10-16 fixes to allow compilation uner modern Arduino IDE 2.3.2
133/// \version 1.6 2026-10-24 Fixed some incorrect phonemen definitions, reported by Andrew Davie
134///
135
136#ifndef SPEAKJET_h
137#define SPEAKJET_h
138
139#if ARDUINO >= 100
140#include <Arduino.h>
141#else
142#include <wiring.h>
143#include <avr/pgmspace.h>
144// These defs cause trouble on some versions of Arduino
145#undef abs
146#undef double
147#undef round
148#endif
149
150#include <SoftwareSerial.h>
151
152/////////////////////////////////////////////////////////////////////
153/// \class SpeakJet SpeakJet.h <SpeakJet.h>
154/// \brief Driver object for SpeakJet chips such as on SparkFun
155/// VoiceBox shield https://www.sparkfun.com/products/10661
156///
157/// Uses SoftwareSerial class to send command codes to the SpeakJet chip.
158/// Supports a wide range of funcitons for speaking words, phrases, numbers and strings of digits.
159///
160class SpeakJet : public SoftwareSerial
161{
162public:
163
164 /// \brief Structure for translating text words into SpeakJet codes.
165 ///
166 /// word is a pointer to the ASCII text of the word to be pronounced.
167 /// codes is an array of SpeakJet phoneme codes that will be used to speak the word.
168 /// It must end with EndOfPhrase (0xff).
169 /// The entire dictionary must also be in PROGMEM.
170 /// See the included dicitonary files standardDict.cpp and numericDict.cpp for examples on
171 /// how to achieve this.
172 /// Alternatively use convertDict.pl to create correctly structured Dictionary from a .dic text file.
173 typedef struct
174 {
175 const char* word; ///< ASCII text of word to speak (must be in PROGMEM)
176 const uint8_t* codes; ///< Array of speakjet control codes. End with EndOfPhrase (0xff) (must be in PROGMEM)
178
179 /// Command codes for SpeakJet chip.
180 /// These can be passed to speakCode().
181 /// Arrays of them can be passed to speakCodes(), with an EndOfPhrase at the end.
182 /// Based on http://www.sparkfun.com/datasheets/Components/General/speakjet-usermanual.pdf
183 typedef enum
184 {
185 Pause0 = 0, ///< Pause 0ms
186 Pause1 = 1, ///< Pause 100ms
187 Pause2 = 2, ///< Pause 200ms
188 Pause3 = 3, ///< Pause 700ms
189 Pause4 = 4, ///< Pause 30ms
190 Pause5 = 5, ///< Pause 60ms
191 Pause6 = 6, ///< Pause 90ms
192 Fast = 7, ///< Next phoneme at 0.5 speed
193 Slow = 8, ///< Next phoneme at 1.5 speed
194 Stress = 14, ///< Next phoneme with some stress
195 Relax = 15, ///< Next phoneme with relaxation
196 Wait = 16, ///< Stops and waits for a Start (see manual)
197 Soft = 18, ///< Soft
198 Volume = 20, ///< Next octet is volume 0 to 127. Default 96
199 Speed = 21, ///< Next octet is speed 0 to 127. Default 114
200 Pitch = 22, ///< Next octet is pitch in Hz = to 255
201 Bend = 23, ///< Next octet is frequency bend to 15. Default is 5
202 PortCtr = 24, ///< Next octet is port control value. See manual. Default is 7
203 Port = 25, ///< Next octet is Port Output Value. See manual. Default is 0
204 Repeat = 26, ///< Next octet is repeat count. 0 to 255
205 CallPhrase = 28, ///< Next octet is EEPROM phrase to play and return. See manual.
206 GotoPhrase = 29, ///< Next octet is EEPROM phgrase to go to. See manual.
207 Delay = 30, ///< Next octet is delay in multiples of 10ms. 0 to 255.
208 Reset = 31, ///< Reset Volume Speed, Pitch, Bend to defaults.
209
210 // 32 to 127 reserved
211
212 // 128 to 254 Sound codes
213 // Phonemes, standard names
214 Phoneme_IY = 128, ///< 70ms Voiced Long Vowel
215 Phoneme_IH = 129, ///< 70ms Voiced Long Vowel
216 Phoneme_EY = 130, ///< 70ms Voiced Long Vowel
217 Phoneme_EH = 131, ///< 70ms Voiced Long Vowel
218 Phoneme_AY = 132, ///< 70ms Voiced Long Vowel
219 Phoneme_AX = 133, ///< 70ms Voiced Long Vowel
220 Phoneme_UX = 134, ///< 70ms Voiced Long Vowel
221 Phoneme_OH = 135, ///< 70ms Voiced Long Vowel
222 Phoneme_AW = 136, ///< 70ms Voiced Long Vowel
223 Phoneme_OW = 137, ///< 70ms Voiced Long Vowel
224 Phoneme_UH = 138, ///< 70ms Voiced Long Vowel
225 Phoneme_UW = 139, ///< 70ms Voiced Long Vowel
226 Phoneme_MM = 140, ///< 70ms Voiced Nasal
227 Phoneme_NE = 141, ///< 70ms Voiced Nasal
228 Phoneme_NO = 142, ///< 70ms Voiced Nasal
229 Phoneme_NGE = 143, ///< 70ms Voiced Nasal
230 Phoneme_NGO = 144, ///< 70ms Voiced Nasal
231 Phoneme_LE = 145, ///< 70ms Voiced Resonate
232 Phoneme_LO = 146, ///< 70ms Voiced Resonate
233 Phoneme_WW = 147, ///< 70ms Voiced Resonate
234 Phoneme_RR = 148, ///< 70ms Voiced Resonate
235 Phoneme_IYRR = 149, ///< 200ms Voiced R Color Vowel
236 Phoneme_EYRR = 150, ///< 200ms Voiced R Color Vowel
237 Phoneme_AXRR = 151, ///< 190ms Voiced R Color Vowel
238 Phoneme_AWRR = 152, ///< 200ms Voiced R Color Vowel
239 Phoneme_OWRR = 153, ///< 185ms Voiced R Color Vowel
240 Phoneme_EYIY = 154, ///< 165ms Voiced Diphthong
241 Phoneme_OHIY = 155, ///< 200ms Voiced Diphthong
242 Phoneme_OWIY = 156, ///< 225ms Voiced Diphthong
243 Phoneme_OHIH = 157, ///< 185ms Voiced Diphthong
244 Phoneme_IYEH = 158, ///< 170ms Voiced Diphthong
245 Phoneme_EHLE = 159, ///< 140ms Voiced Diphthong
246 Phoneme_EHLL = 159, ///< 140ms Voiced Diphthong DUPLICATE?
247 Phoneme_IYUW = 160, ///< 180ms Voiced Diphthong
248 Phoneme_AXUW = 161, ///< 170ms Voiced Diphthong
249 Phoneme_IHWW = 162, ///< 170ms Voiced Diphthong
250 Phoneme_AYWW = 163, ///< 200ms Voiced Diphthong
251 Phoneme_OWWW = 164, ///< 131ms Voiced Diphthong
252 Phoneme_JH = 165, ///< 70ms Voiced Affricate
253 Phoneme_VV = 166, ///< 70ms Voiced Fricative
254 Phoneme_ZZ = 167, ///< 70ms Voiced Fricative
255 Phoneme_ZH = 168, ///< 70ms Voiced Fricative
256 Phoneme_DH = 169, ///< 70ms Voiced Fricative
257 Phoneme_BE = 170, ///< 45ms Voiced Stop
258 Phoneme_BO = 171, ///< 45ms Voiced Stop
259 Phoneme_EB = 172, ///< 10ms Voiced Stop
260 Phoneme_OB = 173, ///< 10ms Voiced Stop
261 Phoneme_DE = 174, ///< 45ms Voiced Stop
262 Phoneme_DO = 175, ///< 45ms Voiced Stop
263 Phoneme_ED = 176, ///< 10ms Voiced Stop
264 Phoneme_OD = 177, ///< 10ms Voiced Stop
265 Phoneme_GE = 178, ///< 55ms Voiced Stop
266 Phoneme_GO = 179, ///< 55ms Voiced Stop
267 Phoneme_EG = 180, ///< 55ms Voiced Stop
268 Phoneme_OG = 181, ///< 55ms Voiced Stop
269 Phoneme_CH = 182, ///< 70ms Voiceless Affricate
270 Phoneme_HE = 183, ///< 70ms Voiceless Fricative
271 Phoneme_HO = 184, ///< 70ms Voiceless Fricative
272 Phoneme_WH = 185, ///< 70ms Voiceless Fricative
273 Phoneme_FF = 186, ///< 70ms Voiceless Fricative
274 Phoneme_SE = 187, ///< 40ms Voiceless Fricative
275 Phoneme_SO = 188, ///< 40ms Voiceless Fricative
276 Phoneme_SH = 189, ///< 50ms Voiceless Fricative
277 Phoneme_TH = 190, ///< 40ms Voiceless Fricative
278 Phoneme_TT = 191, ///< 50ms Voiceless Stop
279 Phoneme_TU = 192, ///< 70ms Voiceless Stop
280 Phoneme_TS = 193, ///< 170ms Voiceless Stop
281 Phoneme_KE = 194, ///< 55ms Voiceless Stop
282 Phoneme_KO = 195, ///< 55ms Voiceless Stop
283 Phoneme_EK = 196, ///< 55ms Voiceless Stop
284 Phoneme_OK = 197, ///< 45ms Voiceless Stop
285 Phoneme_PE = 198, ///< 99ms Voiceless Stop
286 Phoneme_PO = 199, ///< 99ms Voiceless Stop
287 // Robot sound
288 Sound_R0 = 200, ///< 80ms Robot
289 Sound_R1 = 201, ///< 80ms Robot
290 Sound_R2 = 202, ///< 80ms Robot
291 Sound_R3 = 203, ///< 80ms Robot
292 Sound_R4 = 204, ///< 80ms Robot
293 Sound_R5 = 205, ///< 80ms Robot
294 Sound_R6 = 206, ///< 80ms Robot
295 Sound_R7 = 207, ///< 80ms Robot
296 Sound_R8 = 208, ///< 80ms Robot
297 Sound_R9 = 209, ///< 80ms Robot
298 // Alarm sound
299 Sound_A0 = 210, ///< 300ms Alarm
300 Sound_A1 = 211, ///< 101ms Alarm
301 Sound_A2 = 212, ///< 102ms Alarm
302 Sound_A3 = 213, ///< 540ms Alarm
303 Sound_A4 = 214, ///< 530ms Alarm
304 Sound_A5 = 215, ///< 500ms Alarm
305 Sound_A6 = 216, ///< 135ms Alarm
306 Sound_A7 = 217, ///< 600ms Alarm
307 Sound_A8 = 218, ///< 300ms Alarm
308 Sound_A9 = 219, ///< 250ms Alarm
309 // Beeps
310 Sound_B0 = 220, ///< 200ms Beep
311 Sound_B1 = 221, ///< 270ms Beep
312 Sound_B2 = 222, ///< 280ms Beep
313 Sound_B3 = 223, ///< 260ms Beep
314 Sound_B4 = 224, ///< 300ms Beep
315 Sound_B5 = 225, ///< 100ms Beep
316 Sound_B6 = 226, ///< 104ms Beep
317 Sound_B7 = 227, ///< 100ms Beep
318 Sound_B8 = 228, ///< 270ms Beep
319 Sound_B9 = 229, ///< 262ms Beep
320 // Biological
321 Sound_C0 = 230, ///< 160ms Biological
322 Sound_C1 = 231, ///< 300ms Biological
323 Sound_C2 = 232, ///< 182ms Biological
324 Sound_C3 = 233, ///< 120ms Biological
325 Sound_C4 = 234, ///< 175ms Biological
326 Sound_C5 = 235, ///< 350ms Biological
327 Sound_C6 = 236, ///< 160ms Biological
328 Sound_C7 = 237, ///< 260ms Biological
329 Sound_C8 = 238, ///< 95ms Biological
330 Sound_C9 = 239, ///< 75ms Biological
331 // DTMF
332 DTMF_0 = 240, ///< DTMF 0 95ms
333 DTMF_1 = 241, ///< DTMF 1 95ms
334 DTMF_2 = 242, ///< DTMF 2 95ms
335 DTMF_3 = 243, ///< DTMF 3 95ms
336 DTMF_4 = 244, ///< DTMF 4 95ms
337 DTMF_5 = 245, ///< DTMF 5 95ms
338 DTMF_6 = 246, ///< DTMF 6 95ms
339 DTMF_7 = 247, ///< DTMF 7 95ms
340 DTMF_8 = 248, ///< DTMF 8 95ms
341 DTMF_9 = 249, ///< DTMF 9 95ms
342 DTMF_STAR = 250, ///< DTMF * 95ms
343 DTMF_HASH = 251, ///< DTMF # 95ms
344 // Miscellaneous
345 Sound_M0 = 252, ///< Sonar ping 125ms
346 Sound_M1 = 253, ///< Pistol shot 250ms
347 Sound_M2 = 254, ///< WOW 530ms
348
349 EndOfPhrase = 255, ///< End of phrase marker. Required at end of code arrays
350
351 } CommandCodes;
352
353
354 /// Constructor.
355 /// Specifies the Arduino digital pins to use to communicate with the SpeakJet chip.
356 /// The default values of the arguments are suitable for use with the standard SparkFun VoiceBox shield.
357 /// You can have multiple instances to talk to different SpeakJet chips, provided they use
358 /// interface pins.
359 /// \param[in] txPin Digital pin to use to send command codes to the SpeakJet. Defaults to 2.
360 /// \param[in] resetPin Digital pin to use to force a reset of the SpeakJet. Defaults to 3.
361 /// \param[in] readyPin Digital pin to use to read if the SpeakJet is ready for another code.
362 /// Defaults to 4, the SPK pin output from the SpeakJet chip.
363 SpeakJet(uint8_t txPin = 2, uint8_t resetPin = 3, uint8_t readyPin = 4);
364
365 /// Object initialiser.
366 /// This causes the digital interface pins in the constructor to be set for input or output as the case may be
367 /// The SoftwareSerial interface is initialised to 9600 baud, and the SpeakJet is reset by
368 /// forcing the Reset pin high for 100ms.
369 /// \return true if the reset succeeded.
370 bool init();
371
372 /// Reset the SpeakJet chip.
373 /// Forces the Reset pin high for 100ms.
374 bool reset();
375
376 /// Check if the SpeakJet chip is ready
377 /// to receive another code. Reads the state of the readyPin configured in the constructor. Low is ready.
378 /// \return true if it is ready.
379 bool isReady();
380
381 /// Wait until the SpeakJet chip is ready.
382 /// Blocks until isReady() return true.
383 void waitReady();
384
385 /// Speak a single phoneme code.
386 /// Waits until the SpeakJet chip is ready, then sends a single code (one of the CommandCodes enum entries)
387 /// This is the basic function used to send all codes to the chip.
388 /// Can also be used to sen control codes like Pause, Volume Speed etc to control the enunciation of following
389 /// Phonemes.
390 /// Returns after the code has been sent.
391 /// \param[in] code One of the CommandCodes enum entries or a raw code number
392 void speakCode(uint8_t code);
393
394 /// Speak a an array of phoneme codes.
395 /// Waits until the SpeakJet chip is ready, then sends a single code (one of the CommandCodes enum entries)
396 /// This is the basic function used to send all codes to the chip.
397 /// Returns after the code has been sent.
398 /// \param[in] codes Array of command codes, terminated by EndOfPhrase (255)
399 void speakCodes(uint8_t *codes);
400
401 /// Speaks a single dictionary entry
402 /// This low level function sends the code array of a DictionaryEntry to the SpeakJet chip.
403 /// You can call it from your own sketches, but it probably rarely necessary.
404 /// \param[in] dict Pointer to a DictionaryEntry in PROGMEM
405 /// \return true if successful.
406 bool speakDictionaryEntry(const DictionaryEntry* dict);
407
408 /// Speaks a single word from a Dictionary.
409 /// Searches a Dictionary for an exactly matching word and then sends the corresponding codes
410 /// to the SpeakJet chip.
411 /// Caution: A linear search is currently used.
412 /// \param[in] word The word to speak in the dictionary
413 /// \param[in] dict Pointer to the first of a set of DictionaryEntry structures, one for each word in the Dictionary.
414 /// \return true if successful. False if the word is not present in the dictionary.
415 bool speakWordFromDictionary(const char* word, const DictionaryEntry* dict);
416
417 /// Speak a sequence of words from a Dictionary.
418 /// The sequnce of words is spit by whitespace and the individual words are spoken one after another,
419 /// with a Pause1 between each word.
420 /// \param[in] words String of space separated words
421 /// \param[in] dict Pointer to the first of a set of DictionaryEntry structures, one for each word in the Dictionary.
422 /// \return true if successful.
423 bool speakWordsFromDictionary(char* words, const DictionaryEntry* dict);
424
425 /// Speak a word from the standard Dictionary.
426 /// If the word is present in the standard dictionary, the codes will be sent to the SpeakJet chip.
427 /// \param[in] word The word to speak in the dictionary
428 /// \return true if successful.
429 bool speakWord(const char* word);
430
431 /// Speak a sequence of words from a standard Dictionary.
432 /// \param[in] words String of space separated words
433 /// \return true if successful.
434 bool speakWords(char* words);
435
436 /// Speak the digits in a string.
437 /// Each digit (and some punctuation) is spoken one charavcter at a time. Suported are:
438 /// - Digits 0 through 9
439 /// - '-' (sp0ken as "plus")
440 /// - '+' (spoken as "minus")
441 /// - '.' (spoken as "dot")
442 /// Other characters are ignored
443 /// \param[in] digits String of digits to be spoken, one at a time
444 /// \return true if successful.
445 bool speakDigits(const char* digits);
446
447 /// Speaks an integer number from 0 to 99
448 /// This low level function is used internally, and you probably would not need to call it from your sketch.
449 /// See instead speakNumber()
450 /// \param[in] n Integer from 0 to 99. Returns false if the number exceeds 99.
451 /// \return true if successful.
452 bool speakNumber99(uint8_t n);
453
454 /// Speaks an integer number from 0 to 999
455 /// This low level function is used internally, and you probably would not need to call it from your sketch.
456 /// See instead speakNumber()
457 /// \param[in] n Integer from 0 to 99. Returns false if the number exceeds 999.
458 /// \return true if successful.
459 bool speakNumber999(uint16_t n);
460
461 /// Speaks an integer number from 0 to (2^32 -1)
462 /// Converts the integer into an conventional English phrase for saying he number out loud such as:
463 /// 0 -> "zero"
464 /// 9 -> "nine"
465 /// 10 -> "ten"
466 /// 999 -> "nine hundred and ninety nine"
467 /// 1000 -> "one thousand"
468 /// 1001 -> "one thousand and one"
469 /// 65377 -> "sixty five thousand three hundred and seventy seven"
470 /// \param[in] n integer number from 0 to (2^32 -1)
471 /// \return true if successful.
472 bool speakNumber(uint32_t n);
473
474
475private:
476
477 /// The digital out pin used to issue a reset to the SpeakJet chip
478 uint8_t _resetPin;
479
480 /// The digital input pin used to check whether the SpeakJet chip is ready for another code.
481 uint8_t _readyPin;
482
483};
484
485
486/// @example test.pde
487/// Test suite sketch.
488/// Tests all the SpeakJet library calls, and shows how to call them.
489/// Demonstrates the use of custom and standard dictionaries, and the numeric dicitonary
490/// for digits and numbers.
491/// Uses the standard dictionary and therefore links to about 32K in size
492/// which will not fit in some Arduinos.
493/// Tested on Arduino Uno.
494#endif
bool init()
Definition SpeakJet.cpp:28
SpeakJet(uint8_t txPin=2, uint8_t resetPin=3, uint8_t readyPin=4)
Definition SpeakJet.cpp:17
bool speakDigits(const char *digits)
Definition SpeakJet.cpp:133
bool speakWordFromDictionary(const char *word, const DictionaryEntry *dict)
Definition SpeakJet.cpp:87
bool speakNumber(uint32_t n)
Definition SpeakJet.cpp:198
void waitReady()
Definition SpeakJet.cpp:47
bool speakNumber999(uint16_t n)
Definition SpeakJet.cpp:173
bool reset()
Definition SpeakJet.cpp:34
bool speakWordsFromDictionary(char *words, const DictionaryEntry *dict)
Definition SpeakJet.cpp:99
void speakCodes(uint8_t *codes)
Definition SpeakJet.cpp:67
CommandCodes
Definition SpeakJet.h:184
@ Phoneme_KE
55ms Voiceless Stop
Definition SpeakJet.h:281
@ Fast
Next phoneme at 0.5 speed.
Definition SpeakJet.h:192
@ Phoneme_DO
45ms Voiced Stop
Definition SpeakJet.h:262
@ Pause0
Pause 0ms.
Definition SpeakJet.h:185
@ DTMF_9
DTMF 9 95ms.
Definition SpeakJet.h:341
@ Sound_C1
300ms Biological
Definition SpeakJet.h:322
@ EndOfPhrase
End of phrase marker. Required at end of code arrays.
Definition SpeakJet.h:349
@ Phoneme_TH
40ms Voiceless Fricative
Definition SpeakJet.h:277
@ Phoneme_LO
70ms Voiced Resonate
Definition SpeakJet.h:232
@ Phoneme_OWWW
131ms Voiced Diphthong
Definition SpeakJet.h:251
@ Pause5
Pause 60ms.
Definition SpeakJet.h:190
@ Phoneme_DE
45ms Voiced Stop
Definition SpeakJet.h:261
@ Sound_C4
175ms Biological
Definition SpeakJet.h:325
@ Phoneme_IYRR
200ms Voiced R Color Vowel
Definition SpeakJet.h:235
@ Pause1
Pause 100ms.
Definition SpeakJet.h:186
@ Sound_A7
600ms Alarm
Definition SpeakJet.h:306
@ Phoneme_EYRR
200ms Voiced R Color Vowel
Definition SpeakJet.h:236
@ Phoneme_EK
55ms Voiceless Stop
Definition SpeakJet.h:283
@ Phoneme_BO
45ms Voiced Stop
Definition SpeakJet.h:258
@ Phoneme_NO
70ms Voiced Nasal
Definition SpeakJet.h:228
@ Sound_B0
200ms Beep
Definition SpeakJet.h:310
@ Repeat
Next octet is repeat count. 0 to 255.
Definition SpeakJet.h:204
@ Sound_R0
80ms Robot
Definition SpeakJet.h:288
@ Relax
Next phoneme with relaxation.
Definition SpeakJet.h:195
@ Phoneme_AXUW
170ms Voiced Diphthong
Definition SpeakJet.h:248
@ Phoneme_OHIY
200ms Voiced Diphthong
Definition SpeakJet.h:241
@ DTMF_0
DTMF 0 95ms.
Definition SpeakJet.h:332
@ Phoneme_ZH
70ms Voiced Fricative
Definition SpeakJet.h:255
@ Phoneme_EHLL
140ms Voiced Diphthong DUPLICATE?
Definition SpeakJet.h:246
@ Sound_B8
270ms Beep
Definition SpeakJet.h:318
@ Phoneme_OW
70ms Voiced Long Vowel
Definition SpeakJet.h:223
@ DTMF_3
DTMF 3 95ms.
Definition SpeakJet.h:335
@ Sound_A4
530ms Alarm
Definition SpeakJet.h:303
@ Sound_C5
350ms Biological
Definition SpeakJet.h:326
@ Sound_B3
260ms Beep
Definition SpeakJet.h:313
@ Phoneme_GE
55ms Voiced Stop
Definition SpeakJet.h:265
@ Sound_A6
135ms Alarm
Definition SpeakJet.h:305
@ Volume
Next octet is volume 0 to 127. Default 96.
Definition SpeakJet.h:198
@ Phoneme_GO
55ms Voiced Stop
Definition SpeakJet.h:266
@ Sound_M1
Pistol shot 250ms.
Definition SpeakJet.h:346
@ Delay
Next octet is delay in multiples of 10ms. 0 to 255.
Definition SpeakJet.h:207
@ Phoneme_CH
70ms Voiceless Affricate
Definition SpeakJet.h:269
@ Sound_B2
280ms Beep
Definition SpeakJet.h:312
@ Sound_R1
80ms Robot
Definition SpeakJet.h:289
@ DTMF_5
DTMF 5 95ms.
Definition SpeakJet.h:337
@ Phoneme_FF
70ms Voiceless Fricative
Definition SpeakJet.h:273
@ Sound_R9
80ms Robot
Definition SpeakJet.h:297
@ DTMF_1
DTMF 1 95ms.
Definition SpeakJet.h:333
@ Sound_R2
80ms Robot
Definition SpeakJet.h:290
@ Phoneme_VV
70ms Voiced Fricative
Definition SpeakJet.h:253
@ Pause6
Pause 90ms.
Definition SpeakJet.h:191
@ Sound_C7
260ms Biological
Definition SpeakJet.h:328
@ Phoneme_EHLE
140ms Voiced Diphthong
Definition SpeakJet.h:245
@ PortCtr
Next octet is port control value. See manual. Default is 7.
Definition SpeakJet.h:202
@ Sound_A9
250ms Alarm
Definition SpeakJet.h:308
@ Phoneme_RR
70ms Voiced Resonate
Definition SpeakJet.h:234
@ Phoneme_EH
70ms Voiced Long Vowel
Definition SpeakJet.h:217
@ Sound_M2
WOW 530ms.
Definition SpeakJet.h:347
@ Phoneme_UW
70ms Voiced Long Vowel
Definition SpeakJet.h:225
@ DTMF_STAR
DTMF * 95ms.
Definition SpeakJet.h:342
@ Phoneme_OHIH
185ms Voiced Diphthong
Definition SpeakJet.h:243
@ Sound_C9
75ms Biological
Definition SpeakJet.h:330
@ Bend
Next octet is frequency bend to 15. Default is 5.
Definition SpeakJet.h:201
@ Phoneme_IYUW
180ms Voiced Diphthong
Definition SpeakJet.h:247
@ Phoneme_EYIY
165ms Voiced Diphthong
Definition SpeakJet.h:240
@ Phoneme_OB
10ms Voiced Stop
Definition SpeakJet.h:260
@ Phoneme_SH
50ms Voiceless Fricative
Definition SpeakJet.h:276
@ Phoneme_JH
70ms Voiced Affricate
Definition SpeakJet.h:252
@ Phoneme_NGO
70ms Voiced Nasal
Definition SpeakJet.h:230
@ Sound_R4
80ms Robot
Definition SpeakJet.h:292
@ Phoneme_WW
70ms Voiced Resonate
Definition SpeakJet.h:233
@ DTMF_6
DTMF 6 95ms.
Definition SpeakJet.h:338
@ Phoneme_AWRR
200ms Voiced R Color Vowel
Definition SpeakJet.h:238
@ Phoneme_PO
99ms Voiceless Stop
Definition SpeakJet.h:286
@ Sound_A0
300ms Alarm
Definition SpeakJet.h:299
@ Sound_A2
102ms Alarm
Definition SpeakJet.h:301
@ Phoneme_OG
55ms Voiced Stop
Definition SpeakJet.h:268
@ Sound_R7
80ms Robot
Definition SpeakJet.h:295
@ Phoneme_UH
70ms Voiced Long Vowel
Definition SpeakJet.h:224
@ Phoneme_NE
70ms Voiced Nasal
Definition SpeakJet.h:227
@ Phoneme_HO
70ms Voiceless Fricative
Definition SpeakJet.h:271
@ Phoneme_EG
55ms Voiced Stop
Definition SpeakJet.h:267
@ Slow
Next phoneme at 1.5 speed.
Definition SpeakJet.h:193
@ Phoneme_IY
70ms Voiced Long Vowel
Definition SpeakJet.h:214
@ GotoPhrase
Next octet is EEPROM phgrase to go to. See manual.
Definition SpeakJet.h:206
@ Phoneme_EY
70ms Voiced Long Vowel
Definition SpeakJet.h:216
@ Phoneme_OD
10ms Voiced Stop
Definition SpeakJet.h:264
@ Phoneme_BE
45ms Voiced Stop
Definition SpeakJet.h:257
@ Phoneme_OWIY
225ms Voiced Diphthong
Definition SpeakJet.h:242
@ Sound_A3
540ms Alarm
Definition SpeakJet.h:302
@ Phoneme_UX
70ms Voiced Long Vowel
Definition SpeakJet.h:220
@ Phoneme_ED
10ms Voiced Stop
Definition SpeakJet.h:263
@ Phoneme_KO
55ms Voiceless Stop
Definition SpeakJet.h:282
@ Sound_B6
104ms Beep
Definition SpeakJet.h:316
@ Phoneme_DH
70ms Voiced Fricative
Definition SpeakJet.h:256
@ Reset
Reset Volume Speed, Pitch, Bend to defaults.
Definition SpeakJet.h:208
@ Phoneme_EB
10ms Voiced Stop
Definition SpeakJet.h:259
@ Sound_B5
100ms Beep
Definition SpeakJet.h:315
@ Sound_C0
160ms Biological
Definition SpeakJet.h:321
@ Sound_R6
80ms Robot
Definition SpeakJet.h:294
@ Sound_C8
95ms Biological
Definition SpeakJet.h:329
@ Phoneme_SO
40ms Voiceless Fricative
Definition SpeakJet.h:275
@ DTMF_7
DTMF 7 95ms.
Definition SpeakJet.h:339
@ Phoneme_ZZ
70ms Voiced Fricative
Definition SpeakJet.h:254
@ DTMF_4
DTMF 4 95ms.
Definition SpeakJet.h:336
@ Phoneme_IHWW
170ms Voiced Diphthong
Definition SpeakJet.h:249
@ Phoneme_OWRR
185ms Voiced R Color Vowel
Definition SpeakJet.h:239
@ DTMF_HASH
DTMF # 95ms.
Definition SpeakJet.h:343
@ Sound_R8
80ms Robot
Definition SpeakJet.h:296
@ DTMF_8
DTMF 8 95ms.
Definition SpeakJet.h:340
@ Phoneme_LE
70ms Voiced Resonate
Definition SpeakJet.h:231
@ Sound_A1
101ms Alarm
Definition SpeakJet.h:300
@ Phoneme_MM
70ms Voiced Nasal
Definition SpeakJet.h:226
@ Sound_R5
80ms Robot
Definition SpeakJet.h:293
@ Port
Next octet is Port Output Value. See manual. Default is 0.
Definition SpeakJet.h:203
@ Phoneme_OH
70ms Voiced Long Vowel
Definition SpeakJet.h:221
@ Phoneme_IH
70ms Voiced Long Vowel
Definition SpeakJet.h:215
@ Speed
Next octet is speed 0 to 127. Default 114.
Definition SpeakJet.h:199
@ Phoneme_HE
70ms Voiceless Fricative
Definition SpeakJet.h:270
@ Phoneme_AY
70ms Voiced Long Vowel
Definition SpeakJet.h:218
@ Pause2
Pause 200ms.
Definition SpeakJet.h:187
@ Phoneme_TS
170ms Voiceless Stop
Definition SpeakJet.h:280
@ Sound_C2
182ms Biological
Definition SpeakJet.h:323
@ Sound_M0
Sonar ping 125ms.
Definition SpeakJet.h:345
@ Pause3
Pause 700ms.
Definition SpeakJet.h:188
@ Sound_B9
262ms Beep
Definition SpeakJet.h:319
@ Sound_B7
100ms Beep
Definition SpeakJet.h:317
@ Wait
Stops and waits for a Start (see manual).
Definition SpeakJet.h:196
@ Phoneme_SE
40ms Voiceless Fricative
Definition SpeakJet.h:274
@ Sound_C3
120ms Biological
Definition SpeakJet.h:324
@ Phoneme_IYEH
170ms Voiced Diphthong
Definition SpeakJet.h:244
@ Pitch
Next octet is pitch in Hz = to 255.
Definition SpeakJet.h:200
@ CallPhrase
Next octet is EEPROM phrase to play and return. See manual.
Definition SpeakJet.h:205
@ Sound_A5
500ms Alarm
Definition SpeakJet.h:304
@ Phoneme_WH
70ms Voiceless Fricative
Definition SpeakJet.h:272
@ Sound_B4
300ms Beep
Definition SpeakJet.h:314
@ Sound_R3
80ms Robot
Definition SpeakJet.h:291
@ Phoneme_AW
70ms Voiced Long Vowel
Definition SpeakJet.h:222
@ Sound_A8
300ms Alarm
Definition SpeakJet.h:307
@ Phoneme_NGE
70ms Voiced Nasal
Definition SpeakJet.h:229
@ Phoneme_AX
70ms Voiced Long Vowel
Definition SpeakJet.h:219
@ Phoneme_PE
99ms Voiceless Stop
Definition SpeakJet.h:285
@ Phoneme_OK
45ms Voiceless Stop
Definition SpeakJet.h:284
@ Phoneme_TT
50ms Voiceless Stop
Definition SpeakJet.h:278
@ Phoneme_AYWW
200ms Voiced Diphthong
Definition SpeakJet.h:250
@ Stress
Next phoneme with some stress.
Definition SpeakJet.h:194
@ Soft
Soft.
Definition SpeakJet.h:197
@ DTMF_2
DTMF 2 95ms.
Definition SpeakJet.h:334
@ Phoneme_TU
70ms Voiceless Stop
Definition SpeakJet.h:279
@ Sound_C6
160ms Biological
Definition SpeakJet.h:327
@ Phoneme_AXRR
190ms Voiced R Color Vowel
Definition SpeakJet.h:237
@ Pause4
Pause 30ms.
Definition SpeakJet.h:189
@ Sound_B1
270ms Beep
Definition SpeakJet.h:311
bool speakWords(char *words)
Definition SpeakJet.cpp:119
bool speakNumber99(uint8_t n)
Definition SpeakJet.cpp:154
bool speakWord(const char *word)
Definition SpeakJet.cpp:113
bool speakDictionaryEntry(const DictionaryEntry *dict)
Definition SpeakJet.cpp:73
bool isReady()
Definition SpeakJet.cpp:42
void speakCode(uint8_t code)
Definition SpeakJet.cpp:54
Structure for translating text words into SpeakJet codes.
Definition SpeakJet.h:174
const uint8_t * codes
Array of speakjet control codes. End with EndOfPhrase (0xff) (must be in PROGMEM).
Definition SpeakJet.h:176
const char * word
ASCII text of word to speak (must be in PROGMEM).
Definition SpeakJet.h:175