Recorder Engine¶
The Recorder Engine API is a set of functions to facilitate voice recording. The API is integrated with Voice Activity Detection, providing options to enable and disable VAD to control the incoming audio stream. The Recorder Engine also includes possibility to encode the audio stream using AMR or AMRWB formats.
API Reference¶
Functions¶
-
esp_err_t
rec_engine_create
(rec_config_t *cfg)¶ Create recorder engine according to parameters.
- Note
- Sample rate is 16k, 1 channel, 16bits, by default. Upon completion of this function rec_open callback will be triggered.
- Return
- 0: Success
- -1: Error
- Parameters
cfg
: See rec_config_t structure for additional details
-
int
rec_engine_data_read
(uint8_t *buffer, int buffer_size, int waiting_time)¶ Read voice data after REC_EVENT_VAD_START.
- Return
- -2 : timeout of read
- -1 : parameters invalid or task not running.
- 0 : last voice block.
- others: voice block index.
- Parameters
buffer
: data pointerbuffer_size
: Size of buffer, must be equal to REC_ONE_BLOCK_SIZE.waiting_time
: Timeout for reading data. Default time of REC_ONE_BLOCK_SIZE is 100ms, larger than 100ms is recommended.
-
esp_err_t
rec_engine_detect_suspend
(rec_voice_suspend_t flag)¶ Suspend or enable voice detection by vad.
- Return
- 0: Success
- -1: Error
- Parameters
flag
: REC_VOICE_SUSPEND_ON: Voice detection is suspended REC_VOICE_SUSPEND_OFF: Voice detection is not suspended
-
esp_err_t
rec_engine_trigger_start
(void)¶ Start recording by force.
- Return
- 0: Success
- -1: Error
-
esp_err_t
rec_engine_trigger_stop
(void)¶ Stop recording by force.
- Return
- 0: Success
- -1: Error
-
esp_err_t
rec_engine_destroy
(void)¶ Destroy the recorder engine.
- Note
- Upon completion of this function rec_close callback will be triggered.
- Return
- 0: Success
- -1: Error
-
esp_err_t
rec_engine_vad_enable
(bool vad_enable)¶ Disable or enable the VAD(voice activity detection).
- Note
- Enable vad by default. Usage: Call this function before
rec_engine_trigger_start
to disable voice activity detection, Call this funciton afterrec_engine_trigger_stop
to enable voice activity detection. Even if disable voice activity detection, theREC_EVENT_VAD_START
andREC_EVENT_VAD_STOP
events still notified whenrec_engine_trigger_start
andrec_engine_trigger_stop
called. - Return
- 0: Success
- -1: Error
- Parameters
vad_enable
: true is enable vad, false disable vad
-
esp_err_t
rec_engine_enc_enable
(bool enc_enable)¶ Enable the recoder encoding, or not.
- Note
support_encoding
must be set,rec_engine_enc_enable
can be used. Disable encoding by default.- Return
- 0: Success
- -1: Error
- Parameters
enc_enable
: true is enable encoding, false is disable.
-
esp_err_t
rec_engine_enc_data_read
(uint8_t *buffer, int buffer_size, int waiting_time, int *out_size)¶ Read voice data after REC_EVENT_VAD_START.
- Note
support_encoding
andrec_engine_enc_enable
must be set.- Return
- -2 : timeout of read
- -1 : parameters invalid or not encoding mode.
- 0 : success.
- others: voice block index.
- Parameters
buffer
: data pointerbuffer_size
: Size of buffer.waiting_time
: Timeout for reading data.out_size
: Valid size of buffer.
-
esp_err_t
rec_engine_mute_enable
(bool mute_enable)¶ Enable the recoder mute, or not.
- Note
- if enable mute, no data fill the buffer, so the
rec_engine_enc_data_read
andrec_engine_data_read
will be blocked. - Return
- 0: Success
- -1: Error
- Parameters
mute_enable
: true is mute, false is not.
-
esp_err_t
rec_engine_get_wakeup_stat
(bool *wakeup_start_t)¶ Get recorder engine wakeup state.
- Return
- 0: Success
- -1: Error
- Parameters
wakeup_start_t
: true is WAKEUP_START, false is not.
Structures¶
-
struct
rec_config_t
¶ recorder configuration parameters
Public Members
-
int
one_frame_duration_ms
¶ Duration of one frame (optional)
-
int
sensitivity
¶ For response accuracy rate sensitivity. Default 0: 90%, 1: 95%
-
int
vad_off_delay_ms
¶ Vad off delay to stop if no voice is detected
-
int
wakeup_time_ms
¶ Time of wakeup
-
bool
support_encoding
¶ Support encoding data
-
const char *
extension
¶ Encoding format.”amr” or “amrwb” support
-
int
task_core
¶ Recorder task running in core (0 or 1)
-
bool
enable_wwe
¶ Enable Wake Word Engine or not
-
rec_callback
evt_cb
¶ Recorder event callback function
-
void *
user_data
¶ Pointer to user data (optional)
-
int