SP03 Text to Speech Synthesizer

SP03.h

Committer:
yangcq88517
Date:
2016-03-07
Revision:
1:58ab657cd515
Parent:
0:2326b6172834
Child:
2:4090898287d5

File content as of revision 1:58ab657cd515:

#ifndef Smartlab_Drive_SP03
#define Smartlab_Drive_SP03

#include "mbed.h"

class SP03
{
private:
    static const char DEFAULT_ADDRESS = 0xC4;
    static const int CLOCK_RATE = 100000;
    static const char REGISTER_FOR_COMMAND = 0x00;
    static const char REGISTER_FOR_SOFTWARE_REVISION_NUMBER = 0x01;
    static const char SPEAK_OUT_THE_BUFFER = 0x40;

    static const char DEFAULT_SPEECH_PITCH = 0x03;
    
    char _volume;
    
    char _speed;

    I2C i2c_bus;
public :

    static const char SPEED_NORMAL  = 0x05;
    static const char SPEED_FAST = 0x02;
    static const char SPEED_SLOW = 0x06;

    static const char VOLUME_MAX = 0x00;
    static const char VOLUME_MEDIUM = 0x03;
    static const char VOLUME_MIN = 0x06;

    /** Construct
     *
     * @param sda I2C sda signal
     * @param scl I2C scl signal
     */
    SP03(PinName sda, PinName scl);

    /** Set the speed of the speech
     *
     * @param message NULL terminated char array
     */
    void speak(const char * message);

    /** Set the speed of the speech
     *
     * @param speed [SPEED_NORMAL = 0x05, SPEED_FAST = 0x02, SPEED_SLOW = 0x06]
     */
    void setSpeed(char speed);

    /** Set the volume of the speech
     *
     * @param volume [VOLUME_MAX = 0x00, VOLUME_MEDIUM = 0x03, VOLUME_MIN = 0x06]
     */
    void setVolume(char volume);

    /** Check if the SP03 is currently talking
     *
     * @returns
     *  ture device is talking and no command can be send,
     *  false command can be issued
     */
    bool isSpeaking();
};

#endif