SP03 Text to Speech Synthesizer
Revision 0:2326b6172834, committed 2014-05-07
- Comitter:
- yangcq88517
- Date:
- Wed May 07 13:52:08 2014 +0000
- Child:
- 1:58ab657cd515
- Commit message:
- SP03 I2C
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SP03.cpp Wed May 07 13:52:08 2014 +0000 @@ -0,0 +1,49 @@ +#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; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SP03.h Wed May 07 13:52:08 2014 +0000 @@ -0,0 +1,33 @@ +#ifndef Smartlab_Drive_SP03 +#define Smartlab_Drive_SP03 + +#include "SP03SpeechSetting.h" +#include "mbed.h" + +class SP03 +{ +private: + static const uint8_t DEFAULT_ADDRESS = 0xC4; + static const int CLOCK_RATE = 100000; + static const uint8_t REGISTER_FOR_COMMAND = 0x00; + static const uint8_t REGISTER_FOR_SOFTWARE_REVISION_NUMBER = 0x01; + static const uint8_t SPEAK_OUT_THE_BUFFER = 0x40; + static const uint8_t DEFAULT_SPEECH_PITCH = 0x03; + + I2C i2c_bus; + + void _speak(const char message[],SmartLab_SP03::Speech_Speed speed, SmartLab_SP03::Speech_Volume volume,uint8_t pitch); +public : + + SP03(PinName sda, PinName scl); + + void Speak(const char message[]); + + void Speak(const char message[],SmartLab_SP03::Speech_Speed speed, SmartLab_SP03::Speech_Volume volume); + + void Speak(const char message[],SmartLab_SP03::Speech_Speed speed, SmartLab_SP03::Speech_Volume volume,uint8_t pitch); + + bool IsSpeaking(); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SP03SpeechSetting.h Wed May 07 13:52:08 2014 +0000 @@ -0,0 +1,17 @@ +#ifndef Smartlab_Drive_SP03SpeechSetting +#define Smartlab_Drive_SP03SpeechSetting +namespace SmartLab_SP03 +{ +enum Speech_Speed { + NORMAL = 0x05, + FAST = 0x02, + SLOW = 0x06, +}; + +enum Speech_Volume { + MAX = 0x00, + MEDIUM = 0x03, + MIN = 0x06, +}; +} +#endif \ No newline at end of file