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
, into your workspace and update all the submodules. - ESP-IDF support HASH '6ccb4cf5b7d1fdddb8c2492f9cbc926abaf230df'.
export ADF_PATH={ your ESP-ADF's path }
export IDF_PATH={ your ESP-IDF's path }
- Clone
MicroPython
into${ADF_PATH}/micropyton_adf
. - MicroPython support HASH '1f371947309c5ea6023b6d9065415697cbc75578'.
cd ${IDF_PATH}
, and apply the patch of${ADF_PATH}/idf_patches/idf_v3.3_freertos.patch
cd ${ADF_PATH}/micropyton_adf/micropython
, and apply the patch of${ADF_PATH}/micropyton_adf/mpmake.patch
.- select your audio board in
${ADF_PATH}/micropyton_adf/sdkconfig.adf
. cd ${ADF_PATH}/micropyton_adf/micropython/mpy-cross
, runmake -j8
.cd ${ADF_PATH}/micropyton_adf/micropython/ports/esp32
, runmake deploy -j8 BOARD=GENERIC_SPIRAM BAUD=921600 PORT={ your uart port }
.
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-beta1', 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