Speech, Effects and Music with DF Player Mini (module/library)

Engle

Member
Back in the 80’s the most exciting outputs I could muster usually involved LEDs and 7 segment displays. Returning to electronics I’m finding that generating audio is now easy and can be far more informative and fun. The attached module provides the ability for your PICAXE program to speak numbers and sentences by stringing together words or phrases, it can also play music, sound effects and adverts. The adverts I found useful in interrupting idle music to encourage game play of my Buzz Wire Race Game at the village fete, also they provided crash sound effects during background music when the game was played.

With websites like www.ttsmp3.com it’s easy to create and download MP3 tracks for words or entire paragraphs. I’ve put together a foundation set of tracks for some projects in addition to the one’s used in my game. Together with this “DF Player_Mini.basinc” module, the audio tracks make it easy to:

  • Speak numbers up to 65,535 using the macro AudioSpeakNumber(val).
  • Speak decimals assuming a word value represents 10’s, 100’s, or 1000’s, such as AudioSpeakThousandths(4023), which speaks four-point-zero-two-three.
  • Speak numbers with ordinal suffixes like 18th, which has its own audio track; or 28th which would be formed by joining the tracks for twenty and eighth.
  • Speak modifiable sentences by stringing together a sequence of words, phrases and numbers.
  • Recite speech, or play any sound, effects or music, by just pre-recording MP3s that a PICAXE either starts immediately using PlayNow(136, “You finished!”); or starts when the preceding track is finished using PlayMP3(137, “Your time was”).

With the foundation tracks you make spoken reports like the demo program below:

Code:
'Compiler Directives
    #picaxe 20X2
    #no_data
    #no_table
    '@Timing.basinc directive
    #define CLOCK_SET_KHZ 8000

'Pins
    symbol AUDIO_TX = B.0               '@DF_Player_Mini.basinc: PICAXE Serial Tx to DF Player via 1K resistor.
    symbol AUDIO_STATUS = pinB.2        '@DF_Player_Mini.basinc: Busy indication from DF Player is active low after about 230mS.

'Variables
    '@DF_Player_Mini.basinc Variables
    symbol _Audio_Digit = b43           'Assign symbol to any spare Byte.
    symbol _Audio_Integer = w22         'Assign symbol to any spare Word.
    symbol _Audio_Fraction = w23        'Assign symbol to any spare Word.
    symbol _Audio_Track = b48           'Assign symbol to any spare Byte.
    symbol _Audio_Byte = b49            'Assign symbol to any spare Byte.
   
'Constants
    '@DF_Player_Mini.basinc Constants
    symbol AUDIO_VOLUME = 15            '0 to 31(Maximum).  You can assign this symbol to a variable if you don't want fixed volume.
    symbol AUDIO_BAUD = T9600_8         'Tx logic is idle high (T) and 9600 bps, the last characters you adjust to your clock speed.
    symbol AUDIO_ACTIVE = 0             'The AUDIO_STATUS pin is active low, indicating audio playing.
    symbol AUDIO_IDLE = 1               'AUDIO_STATUS high indicates the module is idle or seeking a track to play on the disk.
   
'Modules
    #include "Timing.basinc"
    #include "DF_Player_Mini.basinc"

'Initialisation
    gosub AudioInitialise               'Prepares PICAXE output pin, Resets the DF Player, selects SD input and sets volume.

Main:
    PlayNow(0063, "The system has restarted.")
    PlayMP3(0070, "The cell voltage levels are")
    AudioSpeakThousandths(3423)         'This speaks "three-point-four-two-three".
    PlayMP3(0112, "volts")
    PlayMP3(0030, "and")
    AudioSpeakNumber(3375)              'This speaks "three-thousand-three-hundred-and-seventy-five".
    PlayMP3(0111, "millivolts.")
    PlayMP3(0068, "Warning, the battery is below 20%.")
    PlayMP3(0103, "Internal")
    PlayMP3(0121, "temperature")
    PlayMP3(0105, "is")
    AudioSpeakTenths(354)               'This speaks "thirty-five-point-four".
    PlayMP3(0122, "degrees C.")
    PlayMP3(0104, "External")
    PlayMP3(0121, "temperature")
    PlayMP3(0105, "is")
    AudioSpeakTenths(176)
    PlayMP3(0122, "degrees C.")
    PlayMP3(0106, "Total")
    PlayMP3(0101, "solar")
    PlayMP3(0116, "power")
    PlayMP3(0105, "is")
    AudioSpeakHundreths(1263)           'This speaks "Twelve-point-six-three".
    PlayMP3(0093, "kilo")
    PlayMP3(0117, "watt")
    PlayMP3(0087, "hours")
    PlayMP3(0108, "over the last")
    AudioSpeakNumber(7)
    PlayMP3(0089, "days.")
   
    Pause3S
    goto Main
The attached zip file contains a recording that lets you hear what the demo was like. The staccato of individual words is fine and clear for personal use but to save program space and greatly improve presentation it’s best to join phrases rather than individual words. For my game I also edited tracks to speed up the pace a little and occasionally added a cartoon effect and changed pitch.

The DF Player Mini is referred to as a PICAXE SPE033, which isn’t in the shop; or as a SPE035 Project Board which includes a tiny yet powerful speaker, just note the speaker’s pins are too chunky for breadboard. The DF Player Mini is also widely and cheaply available, just make sure you’re obtaining from a quality source. The PICAXE only needs to monitor the DF Player Busy Signal and send serial data to play or stop MP3 or WAV tracks.

The attached “DF_PLAYER_MINI” file contains lots of useful information and it should be renamed with a “.BASINC” extension, the master file is here .

Please note the audio tracks are not for commercial use, although the majority are from ttsmp3.com using the AI “Alloy” voice and their website claims they don’t have any restrictions. NCH WavePad was used to touch-up the tracks, mainly this was normalising based on peak loudness (RMS) and trimming the start and end to remove small amounts of quiet time.

The audio files and a list of all the tracks can be found here .

My future projects are likely to bias more towards speech feedback in future, particularly with external projects because waterproofing and visibility becomes less of an issue. I’m glad to help if you have any issues. Please also let me know if there’s any potential improvements.
 

Attachments

Engle

Member
Yes, I definitely would have had hours of fun with those :)

I'm surprised that chips haven't come along more since then. The price seems high and quality low unless online services or downloads are used. It’s also nice that DF Player can integrate its day job of supporting lots of general audio playback too.
 
Top