SP03 Text to Speech Synthesizer
SP03.cpp
- Committer:
- yangcq88517
- Date:
- 2014-05-07
- Revision:
- 0:2326b6172834
- Child:
- 1:58ab657cd515
File content as of revision 0:2326b6172834:
#include "SP03.h" SP03::SP03(PinName sda, PinName scl): i2c_bus(sda,scl) { i2c_bus.frequency(CLOCK_RATE); } void SP03::_speak(const char message[],SmartLab_SP03::Speech_Speed speed, SmartLab_SP03::Speech_Volume volume,uint8_t pitch) { char speakout[2]; speakout[0] = REGISTER_FOR_COMMAND; speakout[1] = SPEAK_OUT_THE_BUFFER; int length = 6 + strlen(message); char _message[length]; _message[0] = REGISTER_FOR_COMMAND; _message[1] = 0x00; _message[2] = volume; _message[3] = speed; _message[4] = pitch; for (int i = 5; i < length; i++) _message[i] = message[i - 5]; i2c_bus.write(DEFAULT_ADDRESS, _message, length); i2c_bus.write(DEFAULT_ADDRESS, speakout, 2); } void SP03::Speak(const char message[]) { _speak(message, SmartLab_SP03::NORMAL, SmartLab_SP03::MAX, DEFAULT_SPEECH_PITCH); } void SP03::Speak(const char message[],SmartLab_SP03::Speech_Speed speed, SmartLab_SP03::Speech_Volume volume) { _speak(message, speed, volume, DEFAULT_SPEECH_PITCH); } void SP03::Speak(const char message[],SmartLab_SP03::Speech_Speed speed, SmartLab_SP03::Speech_Volume volume,uint8_t pitch) { _speak(message, speed, volume, pitch); } bool SP03::IsSpeaking() { char m[1]= {REGISTER_FOR_COMMAND}; i2c_bus.write(DEFAULT_ADDRESS,m ,1); i2c_bus.read(DEFAULT_ADDRESS, m, 1); if (m[0] == 0x00) return false; else return true; }