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

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 pointer
  • buffer_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 after rec_engine_trigger_stop to enable voice activity detection. Even if disable voice activity detection, the REC_EVENT_VAD_START and REC_EVENT_VAD_STOP events still notified when rec_engine_trigger_start and rec_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 and rec_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 pointer
  • buffer_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 and rec_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_open open

Recorder open callback function

rec_fetch fetch

Recorder fetch data callback function

rec_close close

Recorder close callback function

rec_callback evt_cb

Recorder event callback function

void *user_data

Pointer to user data (optional)

Macros

REC_ONE_BLOCK_SIZE
DEFAULT_REC_ENGINE_CONFIG()

Type Definitions

typedef void (*rec_callback)(rec_event_type_t type, void *user_data)
typedef esp_err_t (*rec_open)(void **handle)
typedef esp_err_t (*rec_fetch)(void *handle, char *data, int data_size)
typedef esp_err_t (*rec_close)(void *handle)

Enumerations

enum rec_event_type_t

Values:

REC_EVENT_WAKEUP_START
REC_EVENT_WAKEUP_END
REC_EVENT_VAD_START
REC_EVENT_VAD_STOP
enum rec_voice_suspend_t

Values:

REC_VOICE_SUSPEND_OFF
REC_VOICE_SUSPEND_ON