// test
//
// Test suite for SpeakJet class
// Tests all the SpeakJet library calls, and shows how to call them.
// Demonstrates the use of custom and standard dictionaries, and the numeric dictionary
// for digits and numbers.
// Uses the standard dictionary and therefore links to about 32K in size
// which will not fit in some Arduinos.
// Tested on Arduino Uno.
// Copyright (C) 2012 Mike McCauley
#include <SpeakJet.h>
#include <SoftwareSerial.h>
SpeakJet speakjet; // Defaults to txPin = 2, resetPin = 3, readyPin = 4, inverseLogic=false
void setup()
{
Serial.begin(9600);
if (!speakjet.init())
Serial.println("SpeakJet init failed");
}
// Sample arrays of phoneme codes. Each must end with EndOfPhrase (255)
uint8_t seven[] = {8,187,7,131,166,131,141,0,255}; // Numeric
uint8_t high_wow[] = {SpeakJet::Stress, SpeakJet::Sound_M2, SpeakJet::EndOfPhrase}; // Symbolic
// Custom test dictionary
// All must be be in PROGMEM
PROGMEM const char dict_word_0[] = "zero";
PROGMEM const char dict_word_1[] = "one";
PROGMEM const uint8_t dict_code_0[] = {167,7,128,7,149,164,0,255};
PROGMEM const uint8_t dict_code_1[] = {147,14,135,8,141,0,255};
PROGMEM const SpeakJet::DictionaryEntry mydict[] =
{
{ dict_word_0, dict_code_0 },
{ dict_word_1, dict_code_1 },
{ 0, 0 }, // Required: Flags the end of the dictionary
};
void loop()
{
if (!speakjet.isReady())
Serial.println("SpeakJet is not ready");
speakjet.waitReady(); // Should be a no-op
// Speak simple numeric codes
delay(1000);
speakjet.speakCode(128); // \IY
// Speak symbolically defined codes
delay(1000);
speakjet.speakCode(SpeakJet::Phoneme_EH);
delay(1000);
// Speak arrays of codes
speakjet.speakCodes(high_wow);
delay(1000);
speakjet.speakCodes(seven);
// Speak a word from a custom dictionary
delay(1000);
if (!speakjet.speakWordFromDictionary("zero", mydict))
Serial.println("speakWordFromDictionary fail 1");
if (speakjet.speakWordFromDictionary("ThisWordDoesNotExist", mydict))
Serial.println("speakWordFromDictionary fail 3");
// Speak a word from the standardDictionary
// Derived from PhraseALator.dic
delay(1000);
if (!speakjet.speakWord("afternoon"))
Serial.println("speakWord fail 1");
if (speakjet.speakWord("ThisWordDoesNotExist"))
Serial.println("speakWord fail 5");
// Speak a sentence of words one at a time from custom dictionary
delay(1000);
if (!speakjet.speakWordsFromDictionary((char*)"zero one zero one one", mydict))
Serial.println("speakWordsFromDictionary fail 1");
// Speak a sentence from the standard dictionary
delay(1000);
speakjet.speakCode(SpeakJet::Stress); // With stress
if (!speakjet.speakWords((char*)"i saw an alligator"))
Serial.println("speakWords fail 1");
speakjet.speakCode(SpeakJet::Reset);
// Speak digits in a number (or IP address) using the standard dictionary
delay(1000);
if (!speakjet.speakDigits("+123.456.7-89.0"))
Serial.println("speakDigit fail 1");
delay(1000);
if (!speakjet.speakNumber(0))
Serial.println("speakNumber fail 1");
delay(1000);
if (!speakjet.speakNumber(1000001))
Serial.println("speakNumber fail 2");
delay(1000);
if (!speakjet.speakNumber(0xffffffff))
Serial.println("speakNumber fail 3");
Serial.println("done");
while (1); // Stop
}