SpeakJet
|
Driver object for SpeakJet chips such as on SparkFun VoiceBox shield https://www.sparkfun.com/products/10661. More...
#include <SpeakJet.h>
Classes | |
struct | DictionaryEntry |
Structure for translating text words into SpeakJet codes. More... | |
Public Types | |
enum | CommandCodes { Pause0 = 0 , Pause1 = 1 , Pause2 = 2 , Pause3 = 3 , Pause4 = 4 , Pause5 = 5 , Pause6 = 6 , Fast = 7 , Slow = 8 , Stress = 14 , Relax = 15 , Wait = 16 , Soft = 18 , Volume = 20 , Speed = 21 , Pitch = 22 , Bend = 23 , PortCtr = 24 , Port = 25 , Repeat = 26 , CallPhrase = 28 , GotoPhrase = 29 , Delay = 30 , Reset = 31 , Phoneme_IY = 128 , Phoneme_IH = 129 , Phoneme_EY = 130 , Phoneme_EH = 131 , Phoneme_AY = 132 , Phoneme_AX = 133 , Phoneme_UX = 134 , Phoneme_OH = 135 , Phoneme_AW = 136 , Phoneme_OW = 137 , Phoneme_UH = 138 , Phoneme_UW = 139 , Phoneme_MM = 140 , Phoneme_NE = 141 , Phoneme_NO = 142 , Phoneme_NGE = 143 , Phoneme_NGO = 144 , Phoneme_LE = 145 , Phoneme_LO = 146 , Phoneme_WW = 147 , Phoneme_RR = 149 , Phoneme_IYRR = 149 , Phoneme_EYRR = 150 , Phoneme_AXRR = 151 , Phoneme_AWRR = 152 , Phoneme_OWRR = 153 , Phoneme_EYIY = 154 , Phoneme_OHIY = 155 , Phoneme_OWIY = 156 , Phoneme_OHIH = 157 , Phoneme_IYEH = 158 , Phoneme_EHLE = 159 , Phoneme_IYUW = 160 , Phoneme_AXUW = 161 , Phoneme_IHWW = 162 , Phoneme_AYWW = 163 , Phoneme_OWWW = 164 , Phoneme_JH = 165 , Phoneme_VV = 166 , Phoneme_ZZ = 167 , Phoneme_ZH = 168 , Phoneme_DH = 169 , Phoneme_BE = 170 , Phoneme_BO = 171 , Phoneme_EB = 172 , Phoneme_OB = 173 , Phoneme_DE = 174 , Phoneme_DO = 174 , Phoneme_ED = 176 , Phoneme_OD = 177 , Phoneme_GE = 178 , Phoneme_GO = 179 , Phoneme_EG = 180 , Phoneme_OG = 181 , Phoneme_CH = 182 , Phoneme_HE = 183 , Phoneme_HO = 184 , Phoneme_WH = 185 , Phoneme_FF = 186 , Phoneme_SE = 187 , Phoneme_SO = 188 , Phoneme_SH = 189 , Phoneme_TH = 190 , Phoneme_TT = 191 , Phoneme_TU = 192 , Phoneme_TS = 193 , Phoneme_KE = 194 , Phoneme_KO = 195 , Phoneme_EK = 196 , Phoneme_OK = 197 , Phoneme_PE = 198 , Phoneme_PO = 199 , Sound_R0 = 200 , Sound_R1 = 201 , Sound_R2 = 202 , Sound_R3 = 203 , Sound_R4 = 204 , Sound_R5 = 205 , Sound_R6 = 206 , Sound_R7 = 207 , Sound_R8 = 208 , Sound_R9 = 209 , Sound_A0 = 210 , Sound_A1 = 211 , Sound_A2 = 212 , Sound_A3 = 213 , Sound_A4 = 214 , Sound_A5 = 215 , Sound_A6 = 216 , Sound_A7 = 217 , Sound_A8 = 218 , Sound_A9 = 219 , Sound_B0 = 220 , Sound_B1 = 221 , Sound_B2 = 222 , Sound_B3 = 223 , Sound_B4 = 224 , Sound_B5 = 225 , Sound_B6 = 226 , Sound_B7 = 227 , Sound_B8 = 228 , Sound_B9 = 229 , Sound_C0 = 230 , Sound_C1 = 231 , Sound_C2 = 232 , Sound_C3 = 233 , Sound_C4 = 234 , Sound_C5 = 235 , Sound_C6 = 236 , Sound_C7 = 237 , Sound_C8 = 238 , Sound_C9 = 239 , DTMF_0 = 240 , DTMF_1 = 241 , DTMF_2 = 242 , DTMF_3 = 243 , DTMF_4 = 244 , DTMF_5 = 245 , DTMF_6 = 246 , DTMF_7 = 247 , DTMF_8 = 248 , DTMF_9 = 249 , DTMF_STAR = 250 , DTMF_HASH = 251 , Sound_M0 = 252 , Sound_M1 = 253 , Sound_M2 = 254 , EndOfPhrase = 255 } |
Public Member Functions | |
SpeakJet (uint8_t txPin=2, uint8_t resetPin=3, uint8_t readyPin=4) | |
bool | init () |
bool | reset () |
bool | isReady () |
void | waitReady () |
void | speakCode (uint8_t code) |
void | speakCodes (uint8_t *codes) |
bool | speakDictionaryEntry (const DictionaryEntry *dict) |
bool | speakWordFromDictionary (const char *word, const DictionaryEntry *dict) |
bool | speakWordsFromDictionary (char *words, const DictionaryEntry *dict) |
bool | speakWord (const char *word) |
bool | speakWords (char *words) |
bool | speakDigits (const char *digits) |
bool | speakNumber99 (uint8_t n) |
bool | speakNumber999 (uint16_t n) |
bool | speakNumber (uint32_t n) |
Driver object for SpeakJet chips such as on SparkFun VoiceBox shield https://www.sparkfun.com/products/10661.
Uses SoftwareSerial class to send command codes to the SpeakJet chip. Supports a wide range of funcitons for speaking words, phrases, numbers and strings of digits.
Command codes for SpeakJet chip. These can be passed to speakCode(). Arrays of them can be passed to speakCodes(), with an EndOfPhrase at the end. Based on http://www.sparkfun.com/datasheets/Components/General/speakjet-usermanual.pdf
SpeakJet::SpeakJet | ( | uint8_t | txPin = 2 , |
uint8_t | resetPin = 3 , |
||
uint8_t | readyPin = 4 |
||
) |
Constructor. Specifies the Arduino digital pins to use to communicate with the SpeakJet chip. The default values of the arguments are suitable for use with the standard SparkFun VoiceBox shield. You can have multiple instances to talk to different SpeakJet chips, provided they use interface pins.
[in] | txPin | Digital pin to use to send command codes to the SpeakJet. Defaults to 2. |
[in] | resetPin | Digital pin to use to force a reset of the SpeakJet. Defaults to 3. |
[in] | readyPin | Digital pin to use to read if the SpeakJet is ready for another code. Defaults to 4, the SPK pin output from the SpeakJet chip. |
bool SpeakJet::init | ( | ) |
Object initialiser. This causes the digital interface pins in the constructor to be set for input or output as the case may be The SoftwareSerial interface is initialised to 9600 baud, and the SpeakJet is reset by forcing the Reset pin high for 100ms.
References reset().
bool SpeakJet::isReady | ( | ) |
Check if the SpeakJet chip is ready to receive another code. Reads the state of the readyPin configured in the constructor. Low is ready.
Referenced by waitReady().
bool SpeakJet::reset | ( | ) |
void SpeakJet::speakCode | ( | uint8_t | code | ) |
Speak a single phoneme code. Waits until the SpeakJet chip is ready, then sends a single code (one of the CommandCodes enum entries) This is the basic function used to send all codes to the chip. Can also be used to sen control codes like Pause, Volume Speed etc to control the enunciation of following Phonemes. Returns after the code has been sent.
[in] | code | One of the CommandCodes enum entries or a raw code number |
References waitReady().
Referenced by speakCodes(), speakDictionaryEntry(), speakDigits(), speakWords(), and speakWordsFromDictionary().
void SpeakJet::speakCodes | ( | uint8_t * | codes | ) |
Speak a an array of phoneme codes. Waits until the SpeakJet chip is ready, then sends a single code (one of the CommandCodes enum entries) This is the basic function used to send all codes to the chip. Returns after the code has been sent.
[in] | codes | Array of command codes, terminated by EndOfPhrase (255) |
References EndOfPhrase, and speakCode().
bool SpeakJet::speakDictionaryEntry | ( | const DictionaryEntry * | dict | ) |
Speaks a single dictionary entry This low level function sends the code array of a DictionaryEntry to the SpeakJet chip. You can call it from your own sketches, but it probably rarely necessary.
[in] | dict | Pointer to a DictionaryEntry in PROGMEM |
References SpeakJet::DictionaryEntry::codes, EndOfPhrase, and speakCode().
Referenced by speakWordFromDictionary().
bool SpeakJet::speakDigits | ( | const char * | digits | ) |
Speak the digits in a string. Each digit (and some punctuation) is spoken one charavcter at a time. Suported are:
[in] | digits | String of digits to be spoken, one at a time |
References Pause1, speakCode(), and speakWordFromDictionary().
bool SpeakJet::speakNumber | ( | uint32_t | n | ) |
Speaks an integer number from 0 to (2^32 -1) Converts the integer into an conventional English phrase for saying he number out loud such as: 0 -> "zero" 9 -> "nine" 10 -> "ten" 999 -> "nine hundred and ninety nine" 1000 -> "one thousand" 1001 -> "one thousand and one" 65377 -> "sixty five thousand three hundred and seventy seven"
[in] | n | integer number from 0 to (2^32 -1) |
References speakNumber99(), speakNumber999(), and speakWordFromDictionary().
bool SpeakJet::speakNumber99 | ( | uint8_t | n | ) |
Speaks an integer number from 0 to 99 This low level function is used internally, and you probably would not need to call it from your sketch. See instead speakNumber()
[in] | n | Integer from 0 to 99. Returns false if the number exceeds 99. |
References speakWordFromDictionary().
Referenced by speakNumber(), and speakNumber999().
bool SpeakJet::speakNumber999 | ( | uint16_t | n | ) |
Speaks an integer number from 0 to 999 This low level function is used internally, and you probably would not need to call it from your sketch. See instead speakNumber()
[in] | n | Integer from 0 to 99. Returns false if the number exceeds 999. |
References speakNumber99(), and speakWordFromDictionary().
Referenced by speakNumber().
bool SpeakJet::speakWord | ( | const char * | word | ) |
Speak a word from the standard Dictionary. If the word is present in the standard dictionary, the codes will be sent to the SpeakJet chip.
[in] | word | The word to speak in the dictionary |
References speakWordFromDictionary().
Referenced by speakWords().
bool SpeakJet::speakWordFromDictionary | ( | const char * | word, |
const DictionaryEntry * | dict | ||
) |
Speaks a single word from a Dictionary. Searches a Dictionary for an exactly matching word and then sends the corresponding codes to the SpeakJet chip. Caution: A linear search is currently used.
[in] | word | The word to speak in the dictionary |
[in] | dict | Pointer to the first of a set of DictionaryEntry structures, one for each word in the Dictionary. |
References speakDictionaryEntry(), and SpeakJet::DictionaryEntry::word.
Referenced by speakDigits(), speakNumber(), speakNumber99(), speakNumber999(), speakWord(), and speakWordsFromDictionary().
bool SpeakJet::speakWords | ( | char * | words | ) |
Speak a sequence of words from a standard Dictionary.
[in] | words | String of space separated words |
References Pause1, speakCode(), and speakWord().
bool SpeakJet::speakWordsFromDictionary | ( | char * | words, |
const DictionaryEntry * | dict | ||
) |
Speak a sequence of words from a Dictionary. The sequnce of words is spit by whitespace and the individual words are spoken one after another, with a Pause1 between each word.
[in] | words | String of space separated words |
[in] | dict | Pointer to the first of a set of DictionaryEntry structures, one for each word in the Dictionary. |
References Pause1, speakCode(), and speakWordFromDictionary().
void SpeakJet::waitReady | ( | ) |
Wait until the SpeakJet chip is ready. Blocks until isReady() return true.
References isReady().
Referenced by speakCode().