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.5.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///
134
135#ifndef SPEAKJET_h
136#define SPEAKJET_h
137
138#if ARDUINO >= 100
139#include <Arduino.h>
140#else
141#include <wiring.h>
142#include <avr/pgmspace.h>
143// These defs cause trouble on some versions of Arduino
144#undef abs
145#undef double
146#undef round
147#endif
148
149#include <SoftwareSerial.h>
150
151/////////////////////////////////////////////////////////////////////
152/// \class SpeakJet SpeakJet.h <SpeakJet.h>
153/// \brief Driver object for SpeakJet chips such as on SparkFun
154/// VoiceBox shield https://www.sparkfun.com/products/10661
155///
156/// Uses SoftwareSerial class to send command codes to the SpeakJet chip.
157/// Supports a wide range of funcitons for speaking words, phrases, numbers and strings of digits.
158///
159class SpeakJet : public SoftwareSerial
160{
161public:
162
163 /// \brief Structure for translating text words into SpeakJet codes.
164 ///
165 /// word is a pointer to the ASCII text of the word to be pronounced.
166 /// codes is an array of SpeakJet phoneme codes that will be used to speak the word.
167 /// It must end with EndOfPhrase (0xff).
168 /// The entire dictionary must also be in PROGMEM.
169 /// See the included dicitonary files standardDict.cpp and numericDict.cpp for examples on
170 /// how to achieve this.
171 /// Alternatively use convertDict.pl to create correctly structured Dictionary from a .dic text file.
172 typedef struct
173 {
174 const char* word; ///< ASCII text of word to speak (must be in PROGMEM)
175 const uint8_t* codes; ///< Array of speakjet control codes. End with EndOfPhrase (0xff) (must be in PROGMEM)
177
178 /// Command codes for SpeakJet chip.
179 /// These can be passed to speakCode().
180 /// Arrays of them can be passed to speakCodes(), with an EndOfPhrase at the end.
181 /// Based on http://www.sparkfun.com/datasheets/Components/General/speakjet-usermanual.pdf
182 typedef enum
183 {
184 Pause0 = 0, ///< Pause 0ms
185 Pause1 = 1, ///< Pause 100ms
186 Pause2 = 2, ///< Pause 200ms
187 Pause3 = 3, ///< Pause 700ms
188 Pause4 = 4, ///< Pause 30ms
189 Pause5 = 5, ///< Pause 60ms
190 Pause6 = 6, ///< Pause 90ms
191 Fast = 7, ///< Next phoneme at 0.5 speed
192 Slow = 8, ///< Next phoneme at 1.5 speed
193 Stress = 14, ///< Next phoneme with some stress
194 Relax = 15, ///< Next phoneme with relaxation
195 Wait = 16, ///< Stops and waits for a Start (see manual)
196 Soft = 18, ///< Stops and waits for a Start (see manual)
197 Volume = 20, ///< Next octet is volume 0 to 127. Default 96
198 Speed = 21, ///< Next octet is speed 0 to 127. Default 114
199 Pitch = 22, ///< Next octet is pitch in Hz = to 255
200 Bend = 23, ///< Next octet is frequency bend to 15. Default is 5
201 PortCtr = 24, ///< Next octet is port control value. See manual. Default is 7
202 Port = 25, ///< Next octet is Port Output Value. See manual. Default is 0
203 Repeat = 26, ///< Next octet is repeat count. 0 to 255
204 CallPhrase = 28, ///< Next octet is EEPROM phrase to play and return. See manual.
205 GotoPhrase = 29, ///< Next octet is EEPROM phgrase to go to. See manual.
206 Delay = 30, ///< Next octet is delay in multiples of 10ms. 0 to 255.
207 Reset = 31, ///< Reset Volume Speed, Pitch, Bend to defaults.
208
209 // 32 to 127 reserved
210
211 // 128 to 254 Sound codes
212 // Phonemes, standard names
213 Phoneme_IY = 128, ///< 70ms Voiced Long Vowel
214 Phoneme_IH = 129, ///< 70ms Voiced Long Vowel
215 Phoneme_EY = 130, ///< 70ms Voiced Long Vowel
216 Phoneme_EH = 131, ///< 70ms Voiced Long Vowel
217 Phoneme_AY = 132, ///< 70ms Voiced Long Vowel
218 Phoneme_AX = 133, ///< 70ms Voiced Long Vowel
219 Phoneme_UX = 134, ///< 70ms Voiced Long Vowel
220 Phoneme_OH = 135, ///< 70ms Voiced Long Vowel
221 Phoneme_AW = 136, ///< 70ms Voiced Long Vowel
222 Phoneme_OW = 137, ///< 70ms Voiced Long Vowel
223 Phoneme_UH = 138, ///< 70ms Voiced Long Vowel
224 Phoneme_UW = 139, ///< 70ms Voiced Long Vowel
225 Phoneme_MM = 140, ///< 70ms Voiced Nasal
226 Phoneme_NE = 141, ///< 70ms Voiced Nasal
227 Phoneme_NO = 142, ///< 70ms Voiced Nasal
228 Phoneme_NGE = 143, ///< 70ms Voiced Nasal
229 Phoneme_NGO = 144, ///< 70ms Voiced Nasal
230 Phoneme_LE = 145, ///< 70ms Voiced Resonate
231 Phoneme_LO = 146, ///< 70ms Voiced Resonate
232 Phoneme_WW = 147, ///< 70ms Voiced Resonate
233 Phoneme_RR = 149, ///< 70ms Voiced Resonate
234 Phoneme_IYRR = 149, ///< 200ms Voiced R Color Vowel
235 Phoneme_EYRR = 150, ///< 200ms Voiced R Color Vowel
236 Phoneme_AXRR = 151, ///< 190ms Voiced R Color Vowel
237 Phoneme_AWRR = 152, ///< 200ms Voiced R Color Vowel
238 Phoneme_OWRR = 153, ///< 185ms Voiced R Color Vowel
239 Phoneme_EYIY = 154, ///< 165ms Voiced Diphthong
240 Phoneme_OHIY = 155, ///< 200ms Voiced Diphthong
241 Phoneme_OWIY = 156, ///< 225ms Voiced Diphthong
242 Phoneme_OHIH = 157, ///< 185ms Voiced Diphthong
243 Phoneme_IYEH = 158, ///< 170ms Voiced Diphthong
244 Phoneme_EHLE = 159, ///< 140ms Voiced Diphthong
245 Phoneme_IYUW = 160, ///< 180ms Voiced Diphthong
246 Phoneme_AXUW = 161, ///< 170ms Voiced Diphthong
247 Phoneme_IHWW = 162, ///< 170ms Voiced Diphthong
248 Phoneme_AYWW = 163, ///< 200ms Voiced Diphthong
249 Phoneme_OWWW = 164, ///< 131ms Voiced Diphthong
250 Phoneme_JH = 165, ///< 70ms Voiced Affricate
251 Phoneme_VV = 166, ///< 70ms Voiced Fricative
252 Phoneme_ZZ = 167, ///< 70ms Voiced Fricative
253 Phoneme_ZH = 168, ///< 70ms Voiced Fricative
254 Phoneme_DH = 169, ///< 70ms Voiced Fricative
255 Phoneme_BE = 170, ///< 45ms Voiced Stop
256 Phoneme_BO = 171, ///< 45ms Voiced Stop
257 Phoneme_EB = 172, ///< 10ms Voiced Stop
258 Phoneme_OB = 173, ///< 10ms Voiced Stop
259 Phoneme_DE = 174, ///< 45ms Voiced Stop
260 Phoneme_DO = 174, ///< 45ms Voiced Stop
261 Phoneme_ED = 176, ///< 10ms Voiced Stop
262 Phoneme_OD = 177, ///< 10ms Voiced Stop
263 Phoneme_GE = 178, ///< 55ms Voiced Stop
264 Phoneme_GO = 179, ///< 55ms Voiced Stop
265 Phoneme_EG = 180, ///< 55ms Voiced Stop
266 Phoneme_OG = 181, ///< 55ms Voiced Stop
267 Phoneme_CH = 182, ///< 70ms Voiceless Affricate
268 Phoneme_HE = 183, ///< 70ms Voiceless Fricative
269 Phoneme_HO = 184, ///< 70ms Voiceless Fricative
270 Phoneme_WH = 185, ///< 70ms Voiceless Fricative
271 Phoneme_FF = 186, ///< 70ms Voiceless Fricative
272 Phoneme_SE = 187, ///< 40ms Voiceless Fricative
273 Phoneme_SO = 188, ///< 40ms Voiceless Fricative
274 Phoneme_SH = 189, ///< 50ms Voiceless Fricative
275 Phoneme_TH = 190, ///< 40ms Voiceless Fricative
276 Phoneme_TT = 191, ///< 50ms Voiceless Stop
277 Phoneme_TU = 192, ///< 70ms Voiceless Stop
278 Phoneme_TS = 193, ///< 170ms Voiceless Stop
279 Phoneme_KE = 194, ///< 55ms Voiceless Stop
280 Phoneme_KO = 195, ///< 55ms Voiceless Stop
281 Phoneme_EK = 196, ///< 55ms Voiceless Stop
282 Phoneme_OK = 197, ///< 45ms Voiceless Stop
283 Phoneme_PE = 198, ///< 99ms Voiceless Stop
284 Phoneme_PO = 199, ///< 99ms Voiceless Stop
285 // Robot sound
286 Sound_R0 = 200, ///< 80ms Robot
287 Sound_R1 = 201, ///< 80ms Robot
288 Sound_R2 = 202, ///< 80ms Robot
289 Sound_R3 = 203, ///< 80ms Robot
290 Sound_R4 = 204, ///< 80ms Robot
291 Sound_R5 = 205, ///< 80ms Robot
292 Sound_R6 = 206, ///< 80ms Robot
293 Sound_R7 = 207, ///< 80ms Robot
294 Sound_R8 = 208, ///< 80ms Robot
295 Sound_R9 = 209, ///< 80ms Robot
296 // Alarm sound
297 Sound_A0 = 210, ///< 300ms Alarm
298 Sound_A1 = 211, ///< 101ms Alarm
299 Sound_A2 = 212, ///< 102ms Alarm
300 Sound_A3 = 213, ///< 540ms Alarm
301 Sound_A4 = 214, ///< 530ms Alarm
302 Sound_A5 = 215, ///< 500ms Alarm
303 Sound_A6 = 216, ///< 135ms Alarm
304 Sound_A7 = 217, ///< 600ms Alarm
305 Sound_A8 = 218, ///< 300ms Alarm
306 Sound_A9 = 219, ///< 250ms Alarm
307 // Beeps
308 Sound_B0 = 220, ///< 200ms Beep
309 Sound_B1 = 221, ///< 270ms Beep
310 Sound_B2 = 222, ///< 280ms Beep
311 Sound_B3 = 223, ///< 260ms Beep
312 Sound_B4 = 224, ///< 300ms Beep
313 Sound_B5 = 225, ///< 100ms Beep
314 Sound_B6 = 226, ///< 104ms Beep
315 Sound_B7 = 227, ///< 100ms Beep
316 Sound_B8 = 228, ///< 270ms Beep
317 Sound_B9 = 229, ///< 262ms Beep
318 // Biological
319 Sound_C0 = 230, ///< 160ms Biological
320 Sound_C1 = 231, ///< 300ms Biological
321 Sound_C2 = 232, ///< 182ms Biological
322 Sound_C3 = 233, ///< 120ms Biological
323 Sound_C4 = 234, ///< 175ms Biological
324 Sound_C5 = 235, ///< 350ms Biological
325 Sound_C6 = 236, ///< 160ms Biological
326 Sound_C7 = 237, ///< 260ms Biological
327 Sound_C8 = 238, ///< 95ms Biological
328 Sound_C9 = 239, ///< 75ms Biological
329 // DTMF
330 DTMF_0 = 240, ///< DTMF 0 95ms
331 DTMF_1 = 241, ///< DTMF 1 95ms
332 DTMF_2 = 242, ///< DTMF 2 95ms
333 DTMF_3 = 243, ///< DTMF 3 95ms
334 DTMF_4 = 244, ///< DTMF 4 95ms
335 DTMF_5 = 245, ///< DTMF 5 95ms
336 DTMF_6 = 246, ///< DTMF 6 95ms
337 DTMF_7 = 247, ///< DTMF 7 95ms
338 DTMF_8 = 248, ///< DTMF 8 95ms
339 DTMF_9 = 249, ///< DTMF 9 95ms
340 DTMF_STAR = 250, ///< DTMF * 95ms
341 DTMF_HASH = 251, ///< DTMF # 95ms
342 // Miscellaneous
343 Sound_M0 = 252, ///< Sonar ping 125ms
344 Sound_M1 = 253, ///< Pistol shot 250ms
345 Sound_M2 = 254, ///< WOW 530ms
346
347 EndOfPhrase = 255, ///< End of phrase marker. Required at end of code arrays
348
349 } CommandCodes;
350
351
352 /// Constructor.
353 /// Specifies the Arduino digital pins to use to communicate with the SpeakJet chip.
354 /// The default values of the arguments are suitable for use with the standard SparkFun VoiceBox shield.
355 /// You can have multiple instances to talk to different SpeakJet chips, provided they use
356 /// interface pins.
357 /// \param[in] txPin Digital pin to use to send command codes to the SpeakJet. Defaults to 2.
358 /// \param[in] resetPin Digital pin to use to force a reset of the SpeakJet. Defaults to 3.
359 /// \param[in] readyPin Digital pin to use to read if the SpeakJet is ready for another code.
360 /// Defaults to 4, the SPK pin output from the SpeakJet chip.
361 SpeakJet(uint8_t txPin = 2, uint8_t resetPin = 3, uint8_t readyPin = 4);
362
363 /// Object initialiser.
364 /// This causes the digital interface pins in the constructor to be set for input or output as the case may be
365 /// The SoftwareSerial interface is initialised to 9600 baud, and the SpeakJet is reset by
366 /// forcing the Reset pin high for 100ms.
367 /// \return true if the reset succeeded.
368 bool init();
369
370 /// Reset the SpeakJet chip.
371 /// Forces the Reset pin high for 100ms.
372 bool reset();
373
374 /// Check if the SpeakJet chip is ready
375 /// to receive another code. Reads the state of the readyPin configured in the constructor. Low is ready.
376 /// \return true if it is ready.
377 bool isReady();
378
379 /// Wait until the SpeakJet chip is ready.
380 /// Blocks until isReady() return true.
381 void waitReady();
382
383 /// Speak a single phoneme code.
384 /// Waits until the SpeakJet chip is ready, then sends a single code (one of the CommandCodes enum entries)
385 /// This is the basic function used to send all codes to the chip.
386 /// Can also be used to sen control codes like Pause, Volume Speed etc to control the enunciation of following
387 /// Phonemes.
388 /// Returns after the code has been sent.
389 /// \param[in] code One of the CommandCodes enum entries or a raw code number
390 void speakCode(uint8_t code);
391
392 /// Speak a an array of phoneme codes.
393 /// Waits until the SpeakJet chip is ready, then sends a single code (one of the CommandCodes enum entries)
394 /// This is the basic function used to send all codes to the chip.
395 /// Returns after the code has been sent.
396 /// \param[in] codes Array of command codes, terminated by EndOfPhrase (255)
397 void speakCodes(uint8_t *codes);
398
399 /// Speaks a single dictionary entry
400 /// This low level function sends the code array of a DictionaryEntry to the SpeakJet chip.
401 /// You can call it from your own sketches, but it probably rarely necessary.
402 /// \param[in] dict Pointer to a DictionaryEntry in PROGMEM
403 /// \return true if successful.
404 bool speakDictionaryEntry(const DictionaryEntry* dict);
405
406 /// Speaks a single word from a Dictionary.
407 /// Searches a Dictionary for an exactly matching word and then sends the corresponding codes
408 /// to the SpeakJet chip.
409 /// Caution: A linear search is currently used.
410 /// \param[in] word The word to speak in the dictionary
411 /// \param[in] dict Pointer to the first of a set of DictionaryEntry structures, one for each word in the Dictionary.
412 /// \return true if successful. False if the word is not present in the dictionary.
413 bool speakWordFromDictionary(const char* word, const DictionaryEntry* dict);
414
415 /// Speak a sequence of words from a Dictionary.
416 /// The sequnce of words is spit by whitespace and the individual words are spoken one after another,
417 /// with a Pause1 between each word.
418 /// \param[in] words String of space separated words
419 /// \param[in] dict Pointer to the first of a set of DictionaryEntry structures, one for each word in the Dictionary.
420 /// \return true if successful.
421 bool speakWordsFromDictionary(char* words, const DictionaryEntry* dict);
422
423 /// Speak a word from the standard Dictionary.
424 /// If the word is present in the standard dictionary, the codes will be sent to the SpeakJet chip.
425 /// \param[in] word The word to speak in the dictionary
426 /// \return true if successful.
427 bool speakWord(const char* word);
428
429 /// Speak a sequence of words from a standard Dictionary.
430 /// \param[in] words String of space separated words
431 /// \return true if successful.
432 bool speakWords(char* words);
433
434 /// Speak the digits in a string.
435 /// Each digit (and some punctuation) is spoken one charavcter at a time. Suported are:
436 /// - Digits 0 through 9
437 /// - '-' (sp0ken as "plus")
438 /// - '+' (spoken as "minus")
439 /// - '.' (spoken as "dot")
440 /// Other characters are ignored
441 /// \param[in] digits String of digits to be spoken, one at a time
442 /// \return true if successful.
443 bool speakDigits(const char* digits);
444
445 /// Speaks an integer number from 0 to 99
446 /// This low level function is used internally, and you probably would not need to call it from your sketch.
447 /// See instead speakNumber()
448 /// \param[in] n Integer from 0 to 99. Returns false if the number exceeds 99.
449 /// \return true if successful.
450 bool speakNumber99(uint8_t n);
451
452 /// Speaks an integer number from 0 to 999
453 /// This low level function is used internally, and you probably would not need to call it from your sketch.
454 /// See instead speakNumber()
455 /// \param[in] n Integer from 0 to 99. Returns false if the number exceeds 999.
456 /// \return true if successful.
457 bool speakNumber999(uint16_t n);
458
459 /// Speaks an integer number from 0 to (2^32 -1)
460 /// Converts the integer into an conventional English phrase for saying he number out loud such as:
461 /// 0 -> "zero"
462 /// 9 -> "nine"
463 /// 10 -> "ten"
464 /// 999 -> "nine hundred and ninety nine"
465 /// 1000 -> "one thousand"
466 /// 1001 -> "one thousand and one"
467 /// 65377 -> "sixty five thousand three hundred and seventy seven"
468 /// \param[in] n integer number from 0 to (2^32 -1)
469 /// \return true if successful.
470 bool speakNumber(uint32_t n);
471
472
473private:
474
475 /// The digital out pin used to issue a reset to the SpeakJet chip
476 uint8_t _resetPin;
477
478 /// The digital input pin used to check whether the SpeakJet chip is ready for another code.
479 uint8_t _readyPin;
480
481};
482
483
484/// @example test.pde
485/// Test suite sketch.
486/// Tests all the SpeakJet library calls, and shows how to call them.
487/// Demonstrates the use of custom and standard dictionaries, and the numeric dicitonary
488/// for digits and numbers.
489/// Uses the standard dictionary and therefore links to about 32K in size
490/// which will not fit in some Arduinos.
491/// Tested on Arduino Uno.
492#endif
Driver object for SpeakJet chips such as on SparkFun VoiceBox shield https://www.sparkfun....
Definition SpeakJet.h:160
bool init()
Definition SpeakJet.cpp:28
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:183
@ Phoneme_KE
55ms Voiceless Stop
Definition SpeakJet.h:279
@ Fast
Next phoneme at 0.5 speed.
Definition SpeakJet.h:191
@ Phoneme_DO
45ms Voiced Stop
Definition SpeakJet.h:260
@ Pause0
Pause 0ms.
Definition SpeakJet.h:184
@ DTMF_9
DTMF 9 95ms.
Definition SpeakJet.h:339
@ Sound_C1
300ms Biological
Definition SpeakJet.h:320
@ EndOfPhrase
End of phrase marker. Required at end of code arrays.
Definition SpeakJet.h:347
@ Phoneme_TH
40ms Voiceless Fricative
Definition SpeakJet.h:275
@ Phoneme_LO
70ms Voiced Resonate
Definition SpeakJet.h:231
@ Phoneme_OWWW
131ms Voiced Diphthong
Definition SpeakJet.h:249
@ Pause5
Pause 60ms.
Definition SpeakJet.h:189
@ Phoneme_DE
45ms Voiced Stop
Definition SpeakJet.h:259
@ Sound_C4
175ms Biological
Definition SpeakJet.h:323
@ Phoneme_IYRR
200ms Voiced R Color Vowel
Definition SpeakJet.h:234
@ Pause1
Pause 100ms.
Definition SpeakJet.h:185
@ Sound_A7
600ms Alarm
Definition SpeakJet.h:304
@ Phoneme_EYRR
200ms Voiced R Color Vowel
Definition SpeakJet.h:235
@ Phoneme_EK
55ms Voiceless Stop
Definition SpeakJet.h:281
@ Phoneme_BO
45ms Voiced Stop
Definition SpeakJet.h:256
@ Phoneme_NO
70ms Voiced Nasal
Definition SpeakJet.h:227
@ Sound_B0
200ms Beep
Definition SpeakJet.h:308
@ Repeat
Next octet is repeat count. 0 to 255.
Definition SpeakJet.h:203
@ Sound_R0
80ms Robot
Definition SpeakJet.h:286
@ Relax
Next phoneme with relaxation.
Definition SpeakJet.h:194
@ Phoneme_AXUW
170ms Voiced Diphthong
Definition SpeakJet.h:246
@ Phoneme_OHIY
200ms Voiced Diphthong
Definition SpeakJet.h:240
@ DTMF_0
DTMF 0 95ms.
Definition SpeakJet.h:330
@ Phoneme_ZH
70ms Voiced Fricative
Definition SpeakJet.h:253
@ Sound_B8
270ms Beep
Definition SpeakJet.h:316
@ Phoneme_OW
70ms Voiced Long Vowel
Definition SpeakJet.h:222
@ DTMF_3
DTMF 3 95ms.
Definition SpeakJet.h:333
@ Sound_A4
530ms Alarm
Definition SpeakJet.h:301
@ Sound_C5
350ms Biological
Definition SpeakJet.h:324
@ Sound_B3
260ms Beep
Definition SpeakJet.h:311
@ Phoneme_GE
55ms Voiced Stop
Definition SpeakJet.h:263
@ Sound_A6
135ms Alarm
Definition SpeakJet.h:303
@ Volume
Next octet is volume 0 to 127. Default 96.
Definition SpeakJet.h:197
@ Phoneme_GO
55ms Voiced Stop
Definition SpeakJet.h:264
@ Sound_M1
Pistol shot 250ms.
Definition SpeakJet.h:344
@ Delay
Next octet is delay in multiples of 10ms. 0 to 255.
Definition SpeakJet.h:206
@ Phoneme_CH
70ms Voiceless Affricate
Definition SpeakJet.h:267
@ Sound_B2
280ms Beep
Definition SpeakJet.h:310
@ Sound_R1
80ms Robot
Definition SpeakJet.h:287
@ DTMF_5
DTMF 5 95ms.
Definition SpeakJet.h:335
@ Phoneme_FF
70ms Voiceless Fricative
Definition SpeakJet.h:271
@ Sound_R9
80ms Robot
Definition SpeakJet.h:295
@ DTMF_1
DTMF 1 95ms.
Definition SpeakJet.h:331
@ Sound_R2
80ms Robot
Definition SpeakJet.h:288
@ Phoneme_VV
70ms Voiced Fricative
Definition SpeakJet.h:251
@ Pause6
Pause 90ms.
Definition SpeakJet.h:190
@ Sound_C7
260ms Biological
Definition SpeakJet.h:326
@ Phoneme_EHLE
140ms Voiced Diphthong
Definition SpeakJet.h:244
@ PortCtr
Next octet is port control value. See manual. Default is 7.
Definition SpeakJet.h:201
@ Sound_A9
250ms Alarm
Definition SpeakJet.h:306
@ Phoneme_RR
70ms Voiced Resonate
Definition SpeakJet.h:233
@ Phoneme_EH
70ms Voiced Long Vowel
Definition SpeakJet.h:216
@ Sound_M2
WOW 530ms.
Definition SpeakJet.h:345
@ Phoneme_UW
70ms Voiced Long Vowel
Definition SpeakJet.h:224
@ DTMF_STAR
DTMF * 95ms.
Definition SpeakJet.h:340
@ Phoneme_OHIH
185ms Voiced Diphthong
Definition SpeakJet.h:242
@ Sound_C9
75ms Biological
Definition SpeakJet.h:328
@ Bend
Next octet is frequency bend to 15. Default is 5.
Definition SpeakJet.h:200
@ Phoneme_IYUW
180ms Voiced Diphthong
Definition SpeakJet.h:245
@ Phoneme_EYIY
165ms Voiced Diphthong
Definition SpeakJet.h:239
@ Phoneme_OB
10ms Voiced Stop
Definition SpeakJet.h:258
@ Phoneme_SH
50ms Voiceless Fricative
Definition SpeakJet.h:274
@ Phoneme_JH
70ms Voiced Affricate
Definition SpeakJet.h:250
@ Phoneme_NGO
70ms Voiced Nasal
Definition SpeakJet.h:229
@ Sound_R4
80ms Robot
Definition SpeakJet.h:290
@ Phoneme_WW
70ms Voiced Resonate
Definition SpeakJet.h:232
@ DTMF_6
DTMF 6 95ms.
Definition SpeakJet.h:336
@ Phoneme_AWRR
200ms Voiced R Color Vowel
Definition SpeakJet.h:237
@ Phoneme_PO
99ms Voiceless Stop
Definition SpeakJet.h:284
@ Sound_A0
300ms Alarm
Definition SpeakJet.h:297
@ Sound_A2
102ms Alarm
Definition SpeakJet.h:299
@ Phoneme_OG
55ms Voiced Stop
Definition SpeakJet.h:266
@ Sound_R7
80ms Robot
Definition SpeakJet.h:293
@ Phoneme_UH
70ms Voiced Long Vowel
Definition SpeakJet.h:223
@ Phoneme_NE
70ms Voiced Nasal
Definition SpeakJet.h:226
@ Phoneme_HO
70ms Voiceless Fricative
Definition SpeakJet.h:269
@ Phoneme_EG
55ms Voiced Stop
Definition SpeakJet.h:265
@ Slow
Next phoneme at 1.5 speed.
Definition SpeakJet.h:192
@ Phoneme_IY
70ms Voiced Long Vowel
Definition SpeakJet.h:213
@ GotoPhrase
Next octet is EEPROM phgrase to go to. See manual.
Definition SpeakJet.h:205
@ Phoneme_EY
70ms Voiced Long Vowel
Definition SpeakJet.h:215
@ Phoneme_OD
10ms Voiced Stop
Definition SpeakJet.h:262
@ Phoneme_BE
45ms Voiced Stop
Definition SpeakJet.h:255
@ Phoneme_OWIY
225ms Voiced Diphthong
Definition SpeakJet.h:241
@ Sound_A3
540ms Alarm
Definition SpeakJet.h:300
@ Phoneme_UX
70ms Voiced Long Vowel
Definition SpeakJet.h:219
@ Phoneme_ED
10ms Voiced Stop
Definition SpeakJet.h:261
@ Phoneme_KO
55ms Voiceless Stop
Definition SpeakJet.h:280
@ Sound_B6
104ms Beep
Definition SpeakJet.h:314
@ Phoneme_DH
70ms Voiced Fricative
Definition SpeakJet.h:254
@ Reset
Reset Volume Speed, Pitch, Bend to defaults.
Definition SpeakJet.h:207
@ Phoneme_EB
10ms Voiced Stop
Definition SpeakJet.h:257
@ Sound_B5
100ms Beep
Definition SpeakJet.h:313
@ Sound_C0
160ms Biological
Definition SpeakJet.h:319
@ Sound_R6
80ms Robot
Definition SpeakJet.h:292
@ Sound_C8
95ms Biological
Definition SpeakJet.h:327
@ Phoneme_SO
40ms Voiceless Fricative
Definition SpeakJet.h:273
@ DTMF_7
DTMF 7 95ms.
Definition SpeakJet.h:337
@ Phoneme_ZZ
70ms Voiced Fricative
Definition SpeakJet.h:252
@ DTMF_4
DTMF 4 95ms.
Definition SpeakJet.h:334
@ Phoneme_IHWW
170ms Voiced Diphthong
Definition SpeakJet.h:247
@ Phoneme_OWRR
185ms Voiced R Color Vowel
Definition SpeakJet.h:238
@ DTMF_HASH
DTMF # 95ms.
Definition SpeakJet.h:341
@ Sound_R8
80ms Robot
Definition SpeakJet.h:294
@ DTMF_8
DTMF 8 95ms.
Definition SpeakJet.h:338
@ Phoneme_LE
70ms Voiced Resonate
Definition SpeakJet.h:230
@ Sound_A1
101ms Alarm
Definition SpeakJet.h:298
@ Phoneme_MM
70ms Voiced Nasal
Definition SpeakJet.h:225
@ Sound_R5
80ms Robot
Definition SpeakJet.h:291
@ Port
Next octet is Port Output Value. See manual. Default is 0.
Definition SpeakJet.h:202
@ Phoneme_OH
70ms Voiced Long Vowel
Definition SpeakJet.h:220
@ Phoneme_IH
70ms Voiced Long Vowel
Definition SpeakJet.h:214
@ Speed
Next octet is speed 0 to 127. Default 114.
Definition SpeakJet.h:198
@ Phoneme_HE
70ms Voiceless Fricative
Definition SpeakJet.h:268
@ Phoneme_AY
70ms Voiced Long Vowel
Definition SpeakJet.h:217
@ Pause2
Pause 200ms.
Definition SpeakJet.h:186
@ Phoneme_TS
170ms Voiceless Stop
Definition SpeakJet.h:278
@ Sound_C2
182ms Biological
Definition SpeakJet.h:321
@ Sound_M0
Sonar ping 125ms.
Definition SpeakJet.h:343
@ Pause3
Pause 700ms.
Definition SpeakJet.h:187
@ Sound_B9
262ms Beep
Definition SpeakJet.h:317
@ Sound_B7
100ms Beep
Definition SpeakJet.h:315
@ Wait
Stops and waits for a Start (see manual)
Definition SpeakJet.h:195
@ Phoneme_SE
40ms Voiceless Fricative
Definition SpeakJet.h:272
@ Sound_C3
120ms Biological
Definition SpeakJet.h:322
@ Phoneme_IYEH
170ms Voiced Diphthong
Definition SpeakJet.h:243
@ Pitch
Next octet is pitch in Hz = to 255.
Definition SpeakJet.h:199
@ CallPhrase
Next octet is EEPROM phrase to play and return. See manual.
Definition SpeakJet.h:204
@ Sound_A5
500ms Alarm
Definition SpeakJet.h:302
@ Phoneme_WH
70ms Voiceless Fricative
Definition SpeakJet.h:270
@ Sound_B4
300ms Beep
Definition SpeakJet.h:312
@ Sound_R3
80ms Robot
Definition SpeakJet.h:289
@ Phoneme_AW
70ms Voiced Long Vowel
Definition SpeakJet.h:221
@ Sound_A8
300ms Alarm
Definition SpeakJet.h:305
@ Phoneme_NGE
70ms Voiced Nasal
Definition SpeakJet.h:228
@ Phoneme_AX
70ms Voiced Long Vowel
Definition SpeakJet.h:218
@ Phoneme_PE
99ms Voiceless Stop
Definition SpeakJet.h:283
@ Phoneme_OK
45ms Voiceless Stop
Definition SpeakJet.h:282
@ Phoneme_TT
50ms Voiceless Stop
Definition SpeakJet.h:276
@ Phoneme_AYWW
200ms Voiced Diphthong
Definition SpeakJet.h:248
@ Stress
Next phoneme with some stress.
Definition SpeakJet.h:193
@ Soft
Stops and waits for a Start (see manual)
Definition SpeakJet.h:196
@ DTMF_2
DTMF 2 95ms.
Definition SpeakJet.h:332
@ Phoneme_TU
70ms Voiceless Stop
Definition SpeakJet.h:277
@ Sound_C6
160ms Biological
Definition SpeakJet.h:325
@ Phoneme_AXRR
190ms Voiced R Color Vowel
Definition SpeakJet.h:236
@ Pause4
Pause 30ms.
Definition SpeakJet.h:188
@ Sound_B1
270ms Beep
Definition SpeakJet.h:309
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:173
const uint8_t * codes
Array of speakjet control codes. End with EndOfPhrase (0xff) (must be in PROGMEM)
Definition SpeakJet.h:175
const char * word
ASCII text of word to speak (must be in PROGMEM)
Definition SpeakJet.h:174