SP03 Text to Speech Synthesizer
Embed:
(wiki syntax)
Show/hide line numbers
SP03.h
00001 #ifndef Smartlab_Drive_SP03 00002 #define Smartlab_Drive_SP03 00003 00004 #include "mbed.h" 00005 /** 00006 * Example: 00007 * @code 00008 * #include "mbed.h" 00009 * #include "SP03.h" 00010 * 00011 * DigitalOut myled(LED1); 00012 * SP03 sp03(p28, p27); 00013 * 00014 * int main() 00015 * { 00016 * sp03.setSpeed(SP03::SPEED_NORMAL); 00017 * 00018 * sp03.setVolume(SP03::VOLUME_MAX); 00019 * 00020 * while(1) { 00021 * if (!sp03.isSpeaking()) { 00022 * myled = 1; 00023 * sp03.speak("Hello CQ 1 2 2 3 4 6 76 7 9 9 08 8"); 00024 * } else 00025 * myled = 0; 00026 * } 00027 * } 00028 * @endcode 00029 */ 00030 class SP03 00031 { 00032 private: 00033 static const char DEFAULT_ADDRESS = 0xC4; 00034 static const int CLOCK_RATE = 100000; 00035 static const char REGISTER_FOR_COMMAND = 0x00; 00036 static const char REGISTER_FOR_SOFTWARE_REVISION_NUMBER = 0x01; 00037 static const char SPEAK_OUT_THE_BUFFER = 0x40; 00038 00039 static const char DEFAULT_SPEECH_PITCH = 0x03; 00040 00041 char _volume; 00042 00043 char _speed; 00044 00045 I2C i2c_bus; 00046 public : 00047 00048 static const char SPEED_NORMAL = 0x05; 00049 static const char SPEED_FAST = 0x02; 00050 static const char SPEED_SLOW = 0x06; 00051 00052 static const char VOLUME_MAX = 0x00; 00053 static const char VOLUME_MEDIUM = 0x03; 00054 static const char VOLUME_MIN = 0x06; 00055 00056 /** Construct 00057 * 00058 * @param sda I2C sda signal 00059 * @param scl I2C scl signal 00060 */ 00061 SP03(PinName sda, PinName scl); 00062 00063 /** Set the speed of the speech 00064 * 00065 * @param message NULL terminated char array 00066 */ 00067 void speak(const char * message); 00068 00069 /** Set the speed of the speech 00070 * 00071 * @param speed [SPEED_NORMAL = 0x05, SPEED_FAST = 0x02, SPEED_SLOW = 0x06] 00072 */ 00073 void setSpeed(char speed); 00074 00075 /** Set the volume of the speech 00076 * 00077 * @param volume [VOLUME_MAX = 0x00, VOLUME_MEDIUM = 0x03, VOLUME_MIN = 0x06] 00078 */ 00079 void setVolume(char volume); 00080 00081 /** Check if the SP03 is currently talking 00082 * 00083 * @returns 00084 * ture device is talking and no command can be send, 00085 * false command can be issued 00086 */ 00087 bool isSpeaking(); 00088 }; 00089 00090 #endif
Generated on Fri Jul 15 2022 05:14:17 by 1.7.2