schmurtzm / MrDiy-Audio-Notifier

MrDiy Audio Notifier (based on esp8266audio) ported to platformio for ESP32
58 stars 23 forks source link

MrDiy Audio Notifier - Schmurtz Edition


MrDiy Audio Notifier is an audio player controlled by MQTT.

It is able to :

MrDiy Audio Notifier is based on esp8266audio library. This repo uses most of the MrDiy's code with some modifications :

/*  Release Notes (yyyy/mm/dd):                                                             */
/*  V0.1 - 2021/12/22 :                                                                     */
/*    - Added these comments, pinouts and additional DAC settings                           */
/*    - Now compatible with platformio                                                      */
/*    - Now compatible with ESP32                                                           */
/*    - Added support for Google Translate TTS                                              */
/*  V0.2 - 2021/12/29 :                                                                     */
/*    - fix playing RTTTL & SAM                                                             */
/*    - added aac playback, useful for many radios                                          */
/*    - added flac playback (working?)                                                      */
/*    - added comments to change the SAMvoice (robot, elf , ET...)                          */
/*    - fix errors msg "connect on fd 63, errno: 118, "Host is unreachable""                */
/*      due to mqtt actions before wifi connects                                            */
/*  V0.3 - 2022/01/03 :                                                                     */
/*    - Migrate to IotWebConf 3.2.0   (Thanks to @markvader)                                */
/*  V0.4 - 2022/01/08 :                                                                     */
/*    - NEW: You can set these options directly in web interface                            */
/*      (These settings are saved & restored after a reboot)                                */
/*           * audio output (no DAC, internal or external DAC), reboot required             */
/*           * audio volume                                                                 */
/*           * default TTS sam voice style can be set in web interface                      */
/*           * default TTS google voice language can be set in web interface                */
/*    - NEW: Firmware update with web interface                                             */
/*    - NEW: MQTT command feedback msg when a problems are detected (topic "answer")        */
/*    - FIX: longer MQTT server name is supported                                           */
/*    - Breaking change : MQTT TTS commands renamed: samvoice /googlevoice                  */
/*    - Less different firmwares + Schmurtz_ESP_Flasher : Windows script for easy flashing  */
/*  V0.5 - 2022/02/18 :                                                                     */
/*    - NEW: increase and decrease volume with MQTT commands                                */
/*    - NEW: increase and decrease volume physical buttons on GPIO                          */
/*  V0.6 - 2022/02/22 :                                                                     */
/*    - FIX: Google TTS : a lot better, almost no hang                                      */
/*  V0.61- 2022/02/22 :                                                                     */
/*    - FIX: SAMVOICE TTS on ESP8266                                                        */
/*    - FIX: Restore generated unique name for MQTT                                         */

How to flash :

Precompiled firmwares are available for ESP8266 (Wemos D1 Mini) and ESP32 (esp32doit-devkit-v4).

To flash it, plug your ESP in USB port, download this full repo and then run _Schmurtz_ESP_Flasher\Schmurtz_ESP_Flasher.bat (Windows only).

How to use :

Just after flashing you will find an AP (wifi network) called "MrDIYNotifier". The default password to connect to this wifi network is "mrdiy.ca". Once connected open web browser and go to http://192.168.4.1 , you will able to configure your wifi parameters, mqtt parameters here and sound parameters (internal DAC, external DAC or no DAC). The "AP password" must be changed (8 characters minimum), keep it in mind, it will be useful to be able to access the web interface later.

Once connected to your wifi, to go back to configuration use this url in your favorite browser : http://MrDIYNotifier-idxxx.local
The login is "admin" and the password is the "AP password" that you have defined during wifi configuration. The precise way in which the wifi works is described in the IotWebConf library readme.

MQTT COMMANDS: ( 'your_mqtt_topic' is the MQTT prefix defined during the setup)

- Play an MP3               MQTT topic: "your_mqtt_topic/play"
                            MQTT load: http://url-to-the-mp3-file/file.mp3
                            PS: supports HTTP only, no HTTPS. -> this could be a solution :
                            https://github.com/earlephilhower/ESP8266Audio/pull/410

- Play an AAC               MQTT topic: "your_mqtt_topic/aac" (OK on ESP32, hard on esp8266)
                            MQTT load: http://url-to-the-aac-file/file.aac

- Play an Icecast Stream    MQTT topic: "your_mqtt_topic/stream"
                            MQTT load: http://url-to-the-icecast-stream/file.mp3
                            example: http://icecast.radiofrance.fr/fiprock-midfi.mp3

- Play a Flac               MQTT topic: "your_mqtt_topic/flac"  
                            (better for ESP32, hard for esp8266)
                            MQTT load: http://url-to-the-flac-file/file.flac

- Play a Ringtone           MQTT topic: "your_mqtt_topic/tone"
                            MQTT load: RTTTL formated text
                            example: Soap:d=8,o=5,b=125:g,a,c6,p,a,4c6,4p,a,g,e,c,4p,4g,a

- Stop Playing              MQTT topic: "your_mqtt_topic/stop"

- Set the Volume            MQTT topic: "your_mqtt_topic/volume"
                            MQTT load: a double between 0.00 and 1.00
                            example: 0.7

- increase/decrease Volume  MQTT topic: "your_mqtt_topic/volume"
                            MQTT load: + or -
                            example: +  -> will increase volume of 0.1

- Say Text                  MQTT topic: "your_mqtt_topic/samvoice"
                            MQTT load: Text to be read
                            example: Hello There. How. Are. You?

- Say Text with Google      MQTT topic: "your_mqtt_topic/googlevoice"
                            MQTT load: Text to be read,language  (language is facultative/optional)
                            example: Hello There. How are you?
                            example: Bonjour, comment allez vous?,fr-FR

For additional details, check the comments at the beginning of the "main.cpp".

How to connect ESP to speaker :

3 possibilities to have a sound output from the ESP (please read ESP8266Audio documentation for more information):

Don't try to drive the speaker directly, the ESP8266 pins can't give enough current to drive even a headphone well and you may end up damaging your device. Instead use a simple transistor 2N2222 or 2N3904 and ~1K resistor:

                            2N3904 (NPN)
                            +---------+
                            |         |     +-|
                            | E  B  C |    / S|
                            +-|--|--|-+    | P|
                              |  |  +------+ E|
                              |  |         | A|
ESP8266-GND ------------------+  |  +------+ K| 
                                 |  |      | E|
ESP8266-I2SOUT (Rx) -----/\/\/\--+  |      \ R|
                                    |       +-|
USB 5V -----------------------------+

You may also want to add a 220uF cap from USB 5V to GND just to help filter out any voltage droop during high volume playback.

Known issues :

Do not hesitate, Participate, there are many ways :

In this project, I will show you how you can use an ESP8266 module or board like the Wemos D1 Mini to play MP3, TTS and RTTTL. It is controlled over MQTT. You will be able to send it an MQTT message with the URL of the MP3 file and it will play it for it. It is also capable to doing basic TTS and playback RTTTL (aka Nokia) ringtone.


Watch the video: click on the image below:

MrDIY Audio Notifier youtube video

Instructions

Please visit Mr DIY Instructables page page for full instructions or watch the video above.

Check out Mr DIY YouTube channel and follow Mr DIY on Twitter. ## Thanks Many thanks to all the authors and contributors to the open source libraries I have used. You have done an amazing job for the community!