SpeakJet
Classes | Public Types | Public Member Functions
SpeakJet Class Reference

Driver object for SpeakJet chips such as on SparkFun VoiceBox shield https://www.sparkfun.com/products/10661. More...

#include <SpeakJet.h>

List of all members.

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 (DictionaryEntry *dict)
bool speakWordFromDictionary (const char *word, DictionaryEntry *dict)
bool speakWordsFromDictionary (char *words, 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)

Detailed Description

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.

Examples:
test.pde.

Member Enumeration Documentation

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

Enumerator:
Pause0 

Pause 0ms.

Pause1 

Pause 100ms.

Pause2 

Pause 200ms.

Pause3 

Pause 700ms.

Pause4 

Pause 30ms.

Pause5 

Pause 60ms.

Pause6 

Pause 90ms.

Fast 

Next phoneme at 0.5 speed.

Slow 

Next phoneme at 1.5 speed.

Stress 

Next phoneme with some stress.

Relax 

Next phoneme with relaxation.

Wait 

Stops and waits for a Start (see manual)

Soft 

Stops and waits for a Start (see manual)

Volume 

Next octet is volume 0 to 127. Default 96.

Speed 

Next octet is speed 0 to 127. Default 114.

Pitch 

Next octet is pitch in Hz = to 255.

Bend 

Next octet is frequency bend to 15. Default is 5.

PortCtr 

Next octet is port control value. See manual. Default is 7.

Port 

Next octet is Port Output Value. See manual. Default is 0.

Repeat 

Next octet is repeat count. 0 to 255.

CallPhrase 

Next octet is EEPROM phrase to play and return. See manual.

GotoPhrase 

Next octet is EEPROM phgrase to go to. See manual.

Delay 

Next octet is delay in multiples of 10ms. 0 to 255.

Reset 

Reset Volume Speed, Pitch, Bend to defaults.

Phoneme_IY 

70ms Voiced Long Vowel

Phoneme_IH 

70ms Voiced Long Vowel

Phoneme_EY 

70ms Voiced Long Vowel

Phoneme_EH 

70ms Voiced Long Vowel

Phoneme_AY 

70ms Voiced Long Vowel

Phoneme_AX 

70ms Voiced Long Vowel

Phoneme_UX 

70ms Voiced Long Vowel

Phoneme_OH 

70ms Voiced Long Vowel

Phoneme_AW 

70ms Voiced Long Vowel

Phoneme_OW 

70ms Voiced Long Vowel

Phoneme_UH 

70ms Voiced Long Vowel

Phoneme_UW 

70ms Voiced Long Vowel

Phoneme_MM 

70ms Voiced Nasal

Phoneme_NE 

70ms Voiced Nasal

Phoneme_NO 

70ms Voiced Nasal

Phoneme_NGE 

70ms Voiced Nasal

Phoneme_NGO 

70ms Voiced Nasal

Phoneme_LE 

70ms Voiced Resonate

Phoneme_LO 

70ms Voiced Resonate

Phoneme_WW 

70ms Voiced Resonate

Phoneme_RR 

70ms Voiced Resonate

Phoneme_IYRR 

200ms Voiced R Color Vowel

Phoneme_EYRR 

200ms Voiced R Color Vowel

Phoneme_AXRR 

190ms Voiced R Color Vowel

Phoneme_AWRR 

200ms Voiced R Color Vowel

Phoneme_OWRR 

185ms Voiced R Color Vowel

Phoneme_EYIY 

165ms Voiced Diphthong

Phoneme_OHIY 

200ms Voiced Diphthong

Phoneme_OWIY 

225ms Voiced Diphthong

Phoneme_OHIH 

185ms Voiced Diphthong

Phoneme_IYEH 

170ms Voiced Diphthong

Phoneme_EHLE 

140ms Voiced Diphthong

Phoneme_IYUW 

180ms Voiced Diphthong

Phoneme_AXUW 

170ms Voiced Diphthong

Phoneme_IHWW 

170ms Voiced Diphthong

Phoneme_AYWW 

200ms Voiced Diphthong

Phoneme_OWWW 

131ms Voiced Diphthong

Phoneme_JH 

70ms Voiced Affricate

Phoneme_VV 

70ms Voiced Fricative

Phoneme_ZZ 

70ms Voiced Fricative

Phoneme_ZH 

70ms Voiced Fricative

Phoneme_DH 

70ms Voiced Fricative

Phoneme_BE 

45ms Voiced Stop

Phoneme_BO 

45ms Voiced Stop

Phoneme_EB 

10ms Voiced Stop

Phoneme_OB 

10ms Voiced Stop

Phoneme_DE 

45ms Voiced Stop

Phoneme_DO 

45ms Voiced Stop

Phoneme_ED 

10ms Voiced Stop

Phoneme_OD 

10ms Voiced Stop

Phoneme_GE 

55ms Voiced Stop

Phoneme_GO 

55ms Voiced Stop

Phoneme_EG 

55ms Voiced Stop

Phoneme_OG 

55ms Voiced Stop

Phoneme_CH 

70ms Voiceless Affricate

Phoneme_HE 

70ms Voiceless Fricative

Phoneme_HO 

70ms Voiceless Fricative

Phoneme_WH 

70ms Voiceless Fricative

Phoneme_FF 

70ms Voiceless Fricative

Phoneme_SE 

40ms Voiceless Fricative

Phoneme_SO 

40ms Voiceless Fricative

Phoneme_SH 

50ms Voiceless Fricative

Phoneme_TH 

40ms Voiceless Fricative

Phoneme_TT 

50ms Voiceless Stop

Phoneme_TU 

70ms Voiceless Stop

Phoneme_TS 

170ms Voiceless Stop

Phoneme_KE 

55ms Voiceless Stop

Phoneme_KO 

55ms Voiceless Stop

Phoneme_EK 

55ms Voiceless Stop

Phoneme_OK 

45ms Voiceless Stop

Phoneme_PE 

99ms Voiceless Stop

Phoneme_PO 

99ms Voiceless Stop

Sound_R0 

80ms Robot

Sound_R1 

80ms Robot

Sound_R2 

80ms Robot

Sound_R3 

80ms Robot

Sound_R4 

80ms Robot

Sound_R5 

80ms Robot

Sound_R6 

80ms Robot

Sound_R7 

80ms Robot

Sound_R8 

80ms Robot

Sound_R9 

80ms Robot

Sound_A0 

300ms Alarm

Sound_A1 

101ms Alarm

Sound_A2 

102ms Alarm

Sound_A3 

540ms Alarm

Sound_A4 

530ms Alarm

Sound_A5 

500ms Alarm

Sound_A6 

135ms Alarm

Sound_A7 

600ms Alarm

Sound_A8 

300ms Alarm

Sound_A9 

250ms Alarm

Sound_B0 

200ms Beep

Sound_B1 

270ms Beep

Sound_B2 

280ms Beep

Sound_B3 

260ms Beep

Sound_B4 

300ms Beep

Sound_B5 

100ms Beep

Sound_B6 

104ms Beep

Sound_B7 

100ms Beep

Sound_B8 

270ms Beep

Sound_B9 

262ms Beep

Sound_C0 

160ms Biological

Sound_C1 

300ms Biological

Sound_C2 

182ms Biological

Sound_C3 

120ms Biological

Sound_C4 

175ms Biological

Sound_C5 

350ms Biological

Sound_C6 

160ms Biological

Sound_C7 

260ms Biological

Sound_C8 

95ms Biological

Sound_C9 

75ms Biological

DTMF_0 

DTMF 0 95ms.

DTMF_1 

DTMF 1 95ms.

DTMF_2 

DTMF 2 95ms.

DTMF_3 

DTMF 3 95ms.

DTMF_4 

DTMF 4 95ms.

DTMF_5 

DTMF 5 95ms.

DTMF_6 

DTMF 6 95ms.

DTMF_7 

DTMF 7 95ms.

DTMF_8 

DTMF 8 95ms.

DTMF_9 

DTMF 9 95ms.

DTMF_STAR 

DTMF * 95ms.

DTMF_HASH 

DTMF # 95ms.

Sound_M0 

Sonar ping 125ms.

Sound_M1 

Pistol shot 250ms.

Sound_M2 

WOW 530ms.

EndOfPhrase 

End of phrase marker. Required at end of code arrays.


Constructor & Destructor Documentation

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.

Parameters:
[in]txPinDigital pin to use to send command codes to the SpeakJet. Defaults to 2.
[in]resetPinDigital pin to use to force a reset of the SpeakJet. Defaults to 3.
[in]readyPinDigital pin to use to read if the SpeakJet is ready for another code. Defaults to 4, the SPK pin output from the SpeakJet chip.

Member Function Documentation

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.

Returns:
true if the reset succeeded.
Examples:
test.pde.

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.

Returns:
true if it is ready.
Examples:
test.pde.

Referenced by waitReady().

bool SpeakJet::reset ( )

Reset the SpeakJet chip. Forces the Reset pin high for 100ms.

Referenced by init().

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.

Parameters:
[in]codeOne of the CommandCodes enum entries or a raw code number
Examples:
test.pde.

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.

Parameters:
[in]codesArray of command codes, terminated by EndOfPhrase (255)
Examples:
test.pde.

References EndOfPhrase, and speakCode().

bool SpeakJet::speakDictionaryEntry ( 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.

Parameters:
[in]dictPointer to a DictionaryEntry in PROGMEM
Returns:
true if successful.

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:

  • Digits 0 through 9
  • '-' (sp0ken as "plus")
  • '+' (spoken as "minus")
  • '.' (spoken as "dot") Other characters are ignored
    Parameters:
    [in]digitsString of digits to be spoken, one at a time
    Returns:
    true if successful.
Examples:
test.pde.

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"

Parameters:
[in]ninteger number from 0 to (2^32 -1)
Returns:
true if successful.
Examples:
test.pde.

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()

Parameters:
[in]nInteger from 0 to 99. Returns false if the number exceeds 99.
Returns:
true if successful.

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()

Parameters:
[in]nInteger from 0 to 99. Returns false if the number exceeds 999.
Returns:
true if successful.

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.

Parameters:
[in]wordThe word to speak in the dictionary
Returns:
true if successful.
Examples:
test.pde.

References speakWordFromDictionary().

Referenced by speakWords().

bool SpeakJet::speakWordFromDictionary ( const char *  word,
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.

Parameters:
[in]wordThe word to speak in the dictionary
[in]dictPointer to the first of a set of DictionaryEntry structures, one for each word in the Dictionary.
Returns:
true if successful. False if the word is not present in the dictionary.
Examples:
test.pde.

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.

Parameters:
[in]wordsString of space separated words
Returns:
true if successful.
Examples:
test.pde.

References Pause1, speakCode(), and speakWord().

bool SpeakJet::speakWordsFromDictionary ( char *  words,
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.

Parameters:
[in]wordsString of space separated words
[in]dictPointer to the first of a set of DictionaryEntry structures, one for each word in the Dictionary.
Returns:
true if successful.
Examples:
test.pde.

References Pause1, speakCode(), and speakWordFromDictionary().

void SpeakJet::waitReady ( )

Wait until the SpeakJet chip is ready. Blocks until isReady() return true.

Examples:
test.pde.

References isReady().

Referenced by speakCode().


The documentation for this class was generated from the following files: