To use this integration, please read the documents of MicroPython
and the README of MicroPython port for ESP32
first.
To build the project, please follow the steps below:
-
Clone
ESP-ADF
,ESP-IDF
,MicroPython
into your workspace and update all the submodules. -
export ADF_PATH={ your ESP-ADF's path }
. -
export IDF_PATH={ your ESP-IDF's path }
. -
ESP-IDF
:- Checkout v5.0.4:
git checkout tags/v5.0.4
. - Install espressif tools:
./install.sh
. - Apply the patch:
git apply ${ADF_PATH}/idf_patches/idf_v5.0_freertos.patch
- Remove the
fatfs
component due to the complie issue:rm ${IDF_PATH}/components/fatfs/CMakeLists.txt
. . $IDF_PATH/export.sh
- Checkout v5.0.4:
-
MicroPython
:- Checkout the supported commit:
git checkout 5114f2c1e -b { branch name you wanted }
. - Apply the patch:
git apply ${ADF_PATH}/micropyton_adf/mp.diff
. cd ${YOUR_MP_PATH}/ports/esp32
- Select the borad with
-D MICROPY_BOARD_DIR=
, build and flash:idf.py build -D MICROPY_BOARD_DIR=${ADF_PATH}/micropython_adf/boards/lyrat43 -D USER_C_MODULES=${ADF_PATH}/micropython_adf/mod/micropython.cmake flash monitor
.
- Checkout the supported commit:
This module implements player and recorder
- player: encapsulates the ADF esp_audio, support local and online resources.
- recorder: record and encoding the voice into file.
NOTICE:
This a beta release as version '0.5-beta2', Classes and methods may be changed by further release.
-
class audio.player([state_callback])
Create a player,
state_callback
is a monitor of player state, when state changed, this callback will be invoked.def cb(state): print(state) #'{{'media_src': 0, 'err_msg': 0, 'status': 1}}', media_src is reserved. p = audio.player(cb) # play music
-
class audio.recorder()
Create recorder.
r = audio.recorder()
-
audio.verno()
version of audio module
>>> audio.verno() '0.5-beta1'
-
audio.mem_info()
Show memory usage.
>>> audio.mem_info() {'dram': 176596, 'inter': 212472, 'mem_total': 1197704}
Audio error type:
audio.AUDIO_OK
: ESP_ERR_AUDIO_NO_ERRORaudio.AUDIO_FAIL
: ESP_ERR_AUDIO_FAILaudio.AUDIO_NO_INPUT_STREAM
: ESP_ERR_AUDIO_NO_INPUT_STREAMaudio.AUDIO_NO_OUTPUT_STREAM
: ESP_ERR_AUDIO_NO_OUTPUT_STREAMaudio.AUDIO_NO_CODEC
: ESP_ERR_AUDIO_NO_CODECaudio.AUDIO_HAL_FAIL
: ESP_ERR_AUDIO_HAL_FAILaudio.AUDIO_MEMORY_LACK
: ESP_ERR_AUDIO_MEMORY_LACKaudio.AUDIO_INVALID_URI
: ESP_ERR_AUDIO_INVALID_URIaudio.AUDIO_INVALID_PARAMETER
: ESP_ERR_AUDIO_INVALID_PARAMETERaudio.AUDIO_NOT_READY
: ESP_ERR_AUDIO_NOT_READYaudio.AUDIO_TIMEOUT
: ESP_ERR_AUDIO_TIMEOUTaudio.AUDIO_ALREADY_EXISTS
: ESP_ERR_AUDIO_ALREADY_EXISTSaudio.AUDIO_LINK_FAIL
: ESP_ERR_AUDIO_LINK_FAILaudio.AUDIO_OPEN
: ESP_ERR_AUDIO_OPENaudio.AUDIO_INPUT
: ESP_ERR_AUDIO_INPUTaudio.AUDIO_PROCESS
: ESP_ERR_AUDIO_PROCESSaudio.AUDIO_OUTPUT
: ESP_ERR_AUDIO_OUTPUTaudio.AUDIO_CLOSE
: ESP_ERR_AUDIO_CLOSE
Audio player now can support mp3
,amr
and wav
, if more types are needed, please add the decoder in function audio_player_create
.
-
player.play(uri, pos=0, sync=False)
Play theuri
from specified position. ifsync = True
, the thread will be suspended until the music finished.uri
formated as "file://sdcard/test.wav" or "https://dl.espressif.com/dl/audio/ff-16b-2c-44100hz.mp3". -
player.stop(termination=player.TERMINATION_NOW)
Stop the player -
player.pause()
Pause the player -
player.resume()
Resume the player -
player.set_vol(vol)
Set the volume of the audio board. -
player.get_vol()
Get the volume of the audio board. -
player.get_state()
Get the state of the player.>>> p = audio.player(None) >>> p.get_state() {'media_src': 0, 'err_msg': 0, 'status': 0}
-
player.pos()
Get the position in bytes of currently played music. -
player.time()
Get the position in microseconds of currently played music.
Player termination type:
TERMINATION_NOW
: TERMINATION_TYPE_NOWTERMINATION_DONE
: TERMINATION_TYPE_DONE
Player status type:
STATUS_UNKNOWN
: AUDIO_STATUS_UNKNOWNSTATUS_RUNNING
: AUDIO_STATUS_RUNNINGSTATUS_PAUSED
: AUDIO_STATUS_PAUSEDSTATUS_STOPPED
: AUDIO_STATUS_STOPPEDSTATUS_FINISHED
: AUDIO_STATUS_FINISHEDSTATUS_ERROR
: AUDIO_STATUS_ERROR
-
recorder.start(path, format=PCM, maxtime=0, endcb=None)
Start the recorder and save the voice intopath
with encoding the date asformat
. Ifmaxtime
> 0, recorder will stop automatic when the duration passed,endcb
will be invoked if notNone
. Ifmaxtime
== 0, recorder will work untilrecorder.stop()
is called. -
recorder.stop()
Stop recording. -
recorder.is_running()
Get the state of recorder,Bool
.
format of final data:
recorder.PCM
recorder.AMR
recorder.MP3
recorder.WAV