音频流

[English]

音频流指的是负责获取和处理音频数据并将处理后的音频发送出去的 音频元素

以下为支持的音频流:

每个流 (stream) 有一个结构体作为输入参数进行初始化,其返回的 audio_element_handle_t 句柄用来调用 audio_element.h 中的函数。大多数流具有 AUDIO_STREAM_READER (读)和 AUDIO_STREAM_WRITER (写)两种类型。例如,可使用 i2s_stream_init()i2s_stream_cfg_t 来设置 I2S 流的类型。

有关 API 的详细信息,请参阅下文。

算法流

算法流 (algorithm stream) 集成声学回声消除 (AEC)、自动增益控制 (AGC)、噪声抑制 (NS) 等前端算法,用于处理收取的音频,常用于 VoIP、语音识别、关键词唤醒等需要预处理的场景。算法流调用 esp-sr,故占用较大内存,且只支持 AUDIO_STREAM_READER 类型。

应用示例

Header File

Functions

audio_element_handle_t algo_stream_init(algorithm_stream_cfg_t *config)

Initialize algorithm stream.

Return

The audio element handle

Parameters
  • config: The algorithm Stream configuration

audio_element_err_t algo_stream_set_delay(audio_element_handle_t el, ringbuf_handle_t ringbuf, int delay_ms)

Set playback signal or recording signal delay when use type2.

Note

The AEC internal buffering mechanism requires that the recording signal is delayed by around 0 - 10 ms compared to the corresponding reference (playback) signal.

Return

  • ESP_OK

  • ESP_FAIL

  • ESP_ERR_INVALID_ARG

Parameters
  • el: Handle of element

  • ringbuf: Handle of ringbuf

  • delay_ms: The delay between playback and recording in ms This delay_ms can be debugged by yourself, you can set the configuration debug_input to true, then get the original input data (left channel is the signal captured from the microphone, right channel is the signal played to the speaker), and check the delay with an audio analysis tool.

esp_err_t algorithm_mono_fix(uint8_t *sbuff, uint32_t len)

Fix I2S mono noise issue.

Note

This API only for ESP32 with I2S 16bits

Return

ESP_OK

Parameters
  • sbuff: I2S data buffer

  • len: I2S data len

Structures

struct algorithm_stream_cfg_t

Algorithm stream configurations.

Public Members

algorithm_stream_input_type_t input_type

Input type of stream

int task_stack

Task stack size

int task_prio

Task peroid

int task_core

The core that task to be created

int out_rb_size

Size of output ringbuffer

bool stack_in_ext

Try to allocate stack in external memory

int rec_linear_factor

The linear amplication factor of record signal

int ref_linear_factor

The linear amplication factor of reference signal

bool debug_input

debug algorithm input data

bool swap_ch

Swap left and right channels

int8_t algo_mask

Choose algorithm to use

int sample_rate

The sampling rate of the input PCM (in Hz)

int mic_ch

MIC channel num

int agc_gain

AGC gain(dB) for voice communication

bool aec_low_cost

AEC uses less cpu and ram resources, but has poor suppression of nonlinear distortion

Macros

ALGORITHM_STREAM_PINNED_TO_CORE
ALGORITHM_STREAM_TASK_PERIOD
ALGORITHM_STREAM_RINGBUFFER_SIZE
ALGORITHM_STREAM_TASK_STACK_SIZE
ALGORITHM_STREAM_DEFAULT_SAMPLE_RATE_HZ
ALGORITHM_STREAM_DEFAULT_SAMPLE_BIT
ALGORITHM_STREAM_DEFAULT_MIC_CHANNELS
ALGORITHM_STREAM_DEFAULT_AGC_GAIN_DB
ALGORITHM_STREAM_DEFAULT_MASK
ALGORITHM_STREAM_CFG_DEFAULT()

Enumerations

enum algorithm_stream_input_type_t

Two types of algorithm stream input method.

Values:

ALGORITHM_STREAM_INPUT_TYPE1 = 0

Type 1 is default used by mini-board, the reference signal and the recording signal are respectively read in from the left channel and the right channel of the same I2S

ALGORITHM_STREAM_INPUT_TYPE2 = 1

As the simple diagram above shows, when type2 is choosen, the recording signal and reference signal should be input by users.

enum algorithm_stream_mask_t

Choose the algorithm to be used.

Values:

ALGORITHM_STREAM_USE_AEC = (0x1 << 0)

Use AEC

ALGORITHM_STREAM_USE_AGC = (0x1 << 1)

Use AGC

ALGORITHM_STREAM_USE_NS = (0x1 << 2)

Use NS

ALGORITHM_STREAM_USE_VAD = (0x1 << 3)

Use VAD

FatFs 流

FatFs 流从 FatFs 文件系统中读取和写入数据,具有读和写两种类型,类型由 audio_stream_type_t 定义。

应用示例

Header File

Functions

audio_element_handle_t fatfs_stream_init(fatfs_stream_cfg_t *config)

Create a handle to an Audio Element to stream data from FatFs to another Element or get data from other elements written to FatFs, depending on the configuration the stream type, either AUDIO_STREAM_READER or AUDIO_STREAM_WRITER.

Return

The Audio Element handle

Parameters
  • config: The configuration

Structures

struct fatfs_stream_cfg_t

FATFS Stream configurations, if any entry is zero then the configuration will be set to default values.

Public Members

audio_stream_type_t type

Stream type

int buf_sz

Audio Element Buffer size

int out_rb_size

Size of output ringbuffer

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

bool ext_stack

Allocate stack on extern ram

bool write_header

Choose to write amrnb/amrwb header in fatfs whether or not (true or false, true means choose to write amrnb header)

Macros

FATFS_STREAM_BUF_SIZE
FATFS_STREAM_TASK_STACK
FATFS_STREAM_TASK_CORE
FATFS_STREAM_TASK_PRIO
FATFS_STREAM_RINGBUFFER_SIZE
FATFS_STREAM_CFG_DEFAULT()

HTTP 流

HTTP 流通过 esp_http_client() 获取和发送数据,具有读和写两种类型,类型由 audio_stream_type_t 定义。AUDIO_STREAM_READER 支持 HTTP、HTTPS 和 HTTP 流直播流协议 (HTTP Live Stream) 等协议,使用前需要连接网络。

应用示例

Header File

Functions

audio_element_handle_t http_stream_init(http_stream_cfg_t *config)

Create a handle to an Audio Element to stream data from HTTP to another Element or get data from other elements sent to HTTP, depending on the configuration the stream type, either AUDIO_STREAM_READER or AUDIO_STREAM_WRITER.

Return

The Audio Element handle

Parameters
  • config: The configuration

esp_err_t http_stream_next_track(audio_element_handle_t el)

Connect to next track in the playlist.

        This function can be used in event_handler of http_stream.
        User can call this function to connect to next track in playlist when he/she gets `HTTP_STREAM_FINISH_TRACK` event

Return

  • ESP_OK on success

  • ESP_FAIL on errors

Parameters
  • el: The http_stream element handle

esp_err_t http_stream_restart(audio_element_handle_t el)
esp_err_t http_stream_fetch_again(audio_element_handle_t el)

Try to fetch the tracks again.

         If this is live stream we will need to keep fetching URIs.

Return

  • ESP_OK on success

  • ESP_ERR_NOT_SUPPORTED if playlist is finished

Parameters
  • el: The http_stream element handle

esp_err_t http_stream_set_server_cert(audio_element_handle_t el, const char *cert)

Set SSL server certification.

Note

EM format as string, if the client requires to verify server

Return

  • ESP_OK on success

Parameters
  • el: The http_stream element handle

  • cert: server certification

Structures

struct http_stream_event_msg_t

Stream event message.

Public Members

http_stream_event_id_t event_id

Event ID

void *http_client

Reference to HTTP Client using by this HTTP Stream

void *buffer

Reference to Buffer using by the Audio Element

int buffer_len

Length of buffer

void *user_data

User data context, from http_stream_cfg_t

audio_element_handle_t el

Audio element context

struct http_stream_cfg_t

HTTP Stream configurations Default value will be used if any entry is zero.

Public Members

audio_stream_type_t type

Type of stream

int out_rb_size

Size of output ringbuffer

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

bool stack_in_ext

Try to allocate stack in external memory

http_stream_event_handle_t event_handle

The hook function for HTTP Stream

void *user_data

User data context

bool auto_connect_next_track

connect next track without open/close

bool enable_playlist_parser

Enable playlist parser

int multi_out_num

The number of multiple output

const char *cert_pem

SSL server certification, PEM format as string, if the client requires to verify server

esp_err_t (*crt_bundle_attach)(void *conf)

Function pointer to esp_crt_bundle_attach. Enables the use of certification bundle for server verification, must be enabled in menuconfig

int request_size

Request data size each time from http_client Defaults use DEFAULT_ELEMENT_BUFFER_LENGTH if set to 0 Need care this setting if audio frame size is small and want low latency playback

int request_range_size

Range size setting for header Range: bytes=start-end Request full range of resource if set to 0 Range size bigger than request size is recommended

const char *user_agent

The User Agent string to send with HTTP requests

Macros

HTTP_STREAM_TASK_STACK
HTTP_STREAM_TASK_CORE
HTTP_STREAM_TASK_PRIO
HTTP_STREAM_RINGBUFFER_SIZE
HTTP_STREAM_CFG_DEFAULT()

Type Definitions

typedef int (*http_stream_event_handle_t)(http_stream_event_msg_t *msg)

Enumerations

enum http_stream_event_id_t

HTTP Stream hook type.

Values:

HTTP_STREAM_PRE_REQUEST = 0x01

The event handler will be called before HTTP Client making the connection to the server

HTTP_STREAM_ON_REQUEST

The event handler will be called when HTTP Client is requesting data, If the fucntion return the value (-1: ESP_FAIL), HTTP Client will be stopped If the fucntion return the value > 0, HTTP Stream will ignore the post_field If the fucntion return the value = 0, HTTP Stream continue send data from post_field (if any)

HTTP_STREAM_ON_RESPONSE

The event handler will be called when HTTP Client is receiving data If the fucntion return the value (-1: ESP_FAIL), HTTP Client will be stopped If the fucntion return the value > 0, HTTP Stream will ignore the read function If the fucntion return the value = 0, HTTP Stream continue read data from HTTP Server

HTTP_STREAM_POST_REQUEST

The event handler will be called after HTTP Client send header and body to the server, before fetching the headers

HTTP_STREAM_FINISH_REQUEST

The event handler will be called after HTTP Client fetch the header and ready to read HTTP body

HTTP_STREAM_RESOLVE_ALL_TRACKS
HTTP_STREAM_FINISH_TRACK
HTTP_STREAM_FINISH_PLAYLIST

I2S 流

I2S 流通过芯片的 I2S、PDM、ADC、DAC 接口接收和发送音频数据,其中 ADC、DAC 功能需要芯片定义 SOC_I2S_SUPPORTS_ADC_DAC。I2S 流还集成自动电平控制 (ALC) 来调节音量,多通道输出和扩展发送音频数据位宽,相关控制位定义在 i2s_stream_cfg_t 中。

应用示例

Header File

Functions

audio_element_handle_t i2s_stream_init(i2s_stream_cfg_t *config)

Create a handle to an Audio Element to stream data from I2S to another Element or get data from other elements sent to I2S, depending on the configuration of stream type is AUDIO_STREAM_READER or AUDIO_STREAM_WRITER.

Note

If I2S stream is enabled with built-in DAC mode, please don’t use I2S_NUM_1. The built-in DAC functions are only supported on I2S0 for the current ESP32 chip.

Return

The Audio Element handle

Parameters
  • config: The configuration

esp_err_t i2s_stream_set_clk(audio_element_handle_t i2s_stream, int rate, int bits, int ch)

Setup clock for I2S Stream, this function is only used with handle created by i2s_stream_init

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] i2s_stream: The i2s element handle

  • [in] rate: Clock rate (in Hz)

  • [in] bits: Audio bit width (8, 16, 24, 32)

  • [in] ch: Number of Audio channels (1: Mono, 2: Stereo). But when set to tdm mode, ch is slot mask.(ex: I2S_TDM_SLOT0 | I2S_TDM_SLOT1 | I2S_TDM_SLOT2 | I2S_TDM_SLOT3)

esp_err_t i2s_alc_volume_set(audio_element_handle_t i2s_stream, int volume)

Setup volume of stream by using ALC.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] i2s_stream: The i2s element handle

  • [in] volume: The volume of stream will be set.

esp_err_t i2s_alc_volume_get(audio_element_handle_t i2s_stream, int *volume)

Get volume of stream.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] i2s_stream: The i2s element handle

  • [in] volume: The volume of stream

esp_err_t i2s_stream_sync_delay(audio_element_handle_t i2s_stream, int delay_ms)

Set sync delay of stream.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] i2s_stream: The i2s element handle

  • [in] delay_ms: The delay of stream

Structures

struct i2s_stream_cfg_t

I2S Stream configurations Default value will be used if any entry is zero.

Public Members

audio_stream_type_t type

Type of stream

i2s_comm_mode_t transmit_mode

I2S transmit mode

i2s_chan_config_t chan_cfg

I2S controller channel configuration

i2s_std_config_t std_cfg

I2S standard mode major configuration that including clock/slot/gpio configuration

i2s_data_bit_width_t expand_src_bits

The source bits per sample when data expand

bool use_alc

It is a flag for ALC. If use ALC, the value is true. Or the value is false

int volume

The volume of audio input data will be set.

int out_rb_size

Size of output ringbuffer

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

bool stack_in_ext

Try to allocate stack in external memory

int multi_out_num

The number of multiple output

bool uninstall_drv

whether uninstall the i2s driver when stream destroyed

bool need_expand

whether to expand i2s data

int buffer_len

Buffer length use for an Element. Note: when ‘bits_per_sample’ is 24 bit, the buffer length must be a multiple of 3. The recommended value is 3600

Macros

I2S_STREAM_TASK_STACK
I2S_STREAM_BUF_SIZE
I2S_STREAM_TASK_PRIO
I2S_STREAM_TASK_CORE
I2S_STREAM_RINGBUFFER_SIZE
I2S_STREAM_CFG_DEFAULT()
I2S_STREAM_CFG_DEFAULT_WITH_PARA(port, rate, bits, stream_type)

PWM 流

一些成本敏感的场景中,音频信号不用 DAC 进行转换,而是使用 PWM 对信号进行调制并经过滤波电路实现。PWM 流实现了音频数据用芯片的 PWM 进行调制并发送的功能,只有 AUDIO_STREAM_WRITER 类型。注意,PWM 的数模转换信噪较低。

应用示例

Header File

Functions

audio_element_handle_t pwm_stream_init(pwm_stream_cfg_t *config)

Initialize PWM stream Only support AUDIO_STREAM_READER type.

Return

The audio element handle

Parameters
  • config: The PWM Stream configuration

esp_err_t pwm_stream_set_clk(audio_element_handle_t pwm_stream, int rate, int bits, int ch)

Setup clock for PWM Stream, this function is only used with handle created by pwm_stream_init

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] pwm_stream: The pwm element handle

  • [in] rate: Clock rate (in Hz)

  • [in] bits: Audio bit width (16, 32)

  • [in] ch: Number of Audio channels (1: Mono, 2: Stereo)

Structures

struct audio_pwm_config_t

PWM audio configurations.

Public Members

timer_group_t tg_num

timer group number (0 - 1)

timer_idx_t timer_num

timer number (0 - 1)

int gpio_num_left

the LEDC output gpio_num, Left channel

int gpio_num_right

the LEDC output gpio_num, Right channel

ledc_channel_t ledc_channel_left

LEDC channel (0 - 7), Corresponding to left channel

ledc_channel_t ledc_channel_right

LEDC channel (0 - 7), Corresponding to right channel

ledc_timer_t ledc_timer_sel

Select the timer source of channel (0 - 3)

ledc_timer_bit_t duty_resolution

ledc pwm bits

uint32_t data_len

ringbuffer size

struct pwm_stream_cfg_t

PWM Stream configurations Default value will be used if any entry is zero.

Public Members

audio_stream_type_t type

Type of stream

audio_pwm_config_t pwm_config

driver configurations

int out_rb_size

Size of output ringbuffer

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

int buffer_len

pwm_stream buffer length

bool ext_stack

Allocate stack on extern ram

Macros

PWM_STREAM_GPIO_NUM_LEFT
PWM_STREAM_GPIO_NUM_RIGHT
PWM_STREAM_TASK_STACK
PWM_STREAM_BUF_SIZE
PWM_STREAM_TASK_PRIO
PWM_STREAM_TASK_CORE
PWM_STREAM_RINGBUFFER_SIZE
PWM_CONFIG_RINGBUFFER_SIZE
PWM_STREAM_CFG_DEFAULT()

原始流

原始流 (raw stream) 用于获取连接的前级元素输出数据,或者为后级连接的元素填充数据,本身不建立线程。AUDIO_STREAM_READER 的应用方式为 [i2s] -> [filter] -> [raw] 或 [i2s] -> [codec-amr] -> [raw],AUDIO_STREAM_WRITER 的应用方式为 [raw]->[codec-mp3]->[i2s]。

应用示例

Header File

Functions

audio_element_handle_t raw_stream_init(raw_stream_cfg_t *cfg)

Initialize RAW stream.

Return

The audio element handle

Parameters
  • cfg: The RAW Stream configuration

int raw_stream_read(audio_element_handle_t pipeline, char *buffer, int buf_size)

Read data from Stream.

Return

Number of bytes actually read.

Parameters
  • pipeline: The audio pipeline handle

  • buffer: The buffer

  • buf_size: Maximum number of bytes to be read.

int raw_stream_write(audio_element_handle_t pipeline, char *buffer, int buf_size)

Write data to Stream.

Return

Number of bytes written

Parameters
  • pipeline: The audio pipeline handle

  • buffer: The buffer

  • buf_size: Number of bytes to write

Structures

struct raw_stream_cfg_t

Raw stream provides APIs to obtain the pipeline data without output stream or fill the pipeline data without input stream. The stream has two types / modes, reader and writer:

  • AUDIO_STREAM_READER, e.g. [i2s]->[filter]->[raw],[i2s]->[codec-amr]->[raw]

  • AUDIO_STREAM_WRITER, e.g. [raw]->[codec-mp3]->[i2s] Raw Stream configurations

Public Members

audio_stream_type_t type

Type of stream

int out_rb_size

Size of output ringbuffer

Macros

RAW_STREAM_RINGBUFFER_SIZE
RAW_STREAM_CFG_DEFAULT()

SPIFFS 流

SPIFFS 流从 SPIFFS 读取和写入音频数据。

应用示例

Header File

Functions

audio_element_handle_t spiffs_stream_init(spiffs_stream_cfg_t *config)

Create a handle to an Audio Element to stream data from SPIFFS to another Element or get data from other elements written to SPIFFS, depending on the configuration the stream type, either AUDIO_STREAM_READER or AUDIO_STREAM_WRITER.

Return

The Audio Element handle

Parameters
  • config: The configuration

Structures

struct spiffs_stream_cfg_t

SPIFFS Stream configuration, if any entry is zero then the configuration will be set to default values.

Public Members

audio_stream_type_t type

Stream type

int buf_sz

Audio Element Buffer size

int out_rb_size

Size of output ringbuffer

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

bool write_header

Choose to write amrnb/armwb header in spiffs whether or not (true or false, true means choose to write amrnb header)

Macros

SPIFFS_STREAM_BUF_SIZE
SPIFFS_STREAM_TASK_STACK
SPIFFS_STREAM_TASK_CORE
SPIFFS_STREAM_TASK_PRIO
SPIFFS_STREAM_RINGBUFFER_SIZE
SPIFFS_STREAM_CFG_DEFAULT()

TCP 客户端流

TCP 客户端流 (TCP client stream) 通过 TCP 读取和写入服务器数据。

应用示例

Header File

Functions

audio_element_handle_t tcp_stream_init(tcp_stream_cfg_t *config)

Initialize a TCP stream to/from an audio element This function creates a TCP stream to/from an audio element depending on the stream type configuration (e.g., AUDIO_STREAM_READER or AUDIO_STREAM_WRITER). The handle of the audio element is the returned.

Return

The audio element handle

Parameters
  • config: The configuration

Structures

struct tcp_stream_event_msg

TCP Stream massage configuration.

Public Members

void *source

Element handle

void *data

Data of input/output

int data_len

Data length of input/output

esp_transport_handle_t sock_fd

handle of socket

struct tcp_stream_cfg_t

TCP Stream configuration, if any entry is zero then the configuration will be set to default values.

Public Members

audio_stream_type_t type

Type of stream

int timeout_ms

time timeout for read/write

int port

TCP port>

char *host

TCP host>

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

bool ext_stack

Allocate stack on extern ram

tcp_stream_event_handle_cb event_handler

TCP stream event callback

void *event_ctx

User context

Macros

TCP_STREAM_DEFAULT_PORT

TCP stream parameters.

TCP_STREAM_TASK_STACK
TCP_STREAM_BUF_SIZE
TCP_STREAM_TASK_PRIO
TCP_STREAM_TASK_CORE
TCP_SERVER_DEFAULT_RESPONSE_LENGTH
TCP_STREAM_CFG_DEFAULT()

Type Definitions

typedef struct tcp_stream_event_msg tcp_stream_event_msg_t

TCP Stream massage configuration.

typedef esp_err_t (*tcp_stream_event_handle_cb)(tcp_stream_event_msg_t *msg, tcp_stream_status_t state, void *event_ctx)

Enumerations

enum tcp_stream_status_t

Values:

TCP_STREAM_STATE_NONE
TCP_STREAM_STATE_CONNECTED

提示音流

提示音流 (tone stream) 读取 tools/audio_tone/mk_audio_tone.py 生成的数据,只支持 AUDIO_STREAM_READER 类型。

应用示例

Header File

Functions

audio_element_handle_t tone_stream_init(tone_stream_cfg_t *config)

Create an Audio Element handle to stream data from flash to another Element, only support AUDIO_STREAM_READER type.

Return

The Audio Element handle

Parameters
  • config: The configuration

Structures

struct tone_stream_cfg_t

TONE Stream configurations, if any entry is zero then the configuration will be set to default values.

Public Members

audio_stream_type_t type

Stream type

int buf_sz

Audio Element Buffer size

int out_rb_size

Size of output ringbuffer

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

const char *label

Label of tone stored in flash. The default value is flash_tone

bool extern_stack

Task stack allocate on the extern ram

bool use_delegate

Read tone partition with esp_delegate. If task stack is on extern ram, this MUST be TRUE

Macros

TONE_STREAM_BUF_SIZE
TONE_STREAM_TASK_STACK
TONE_STREAM_TASK_CORE
TONE_STREAM_TASK_PRIO
TONE_STREAM_RINGBUFFER_SIZE
TONE_STREAM_EXT_STACK
TONE_STREAM_USE_DELEGATE
TONE_STREAM_CFG_DEFAULT()

嵌入 Flash 流

嵌入 Flash 流 (flash-embedding stream) 读取 tools/audio_tone/mk_embed_flash.py 生成的数据,只支持 AUDIO_STREAM_READER 类型。

应用示例

Header File

Functions

audio_element_handle_t embed_flash_stream_init(embed_flash_stream_cfg_t *config)

Create an Audio Element handle to stream data from flash to another Element, only support AUDIO_STREAM_READER type.

Return

The Audio Element handle

Parameters
  • config: The configuration

esp_err_t embed_flash_stream_set_context(audio_element_handle_t embed_stream, const embed_item_info_t *context, int max_num)

Set the embed flash context.

        This function mainly provides information about embed flash data

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] embed_stream: The embed flash element handle

  • [in] context: The embed flash context

  • [in] max_num: The number of embed flash context

Structures

struct embed_flash_stream_cfg_t

Flash-embedding stream configurations, if any entry is zero then the configuration will be set to default values.

Public Members

int buf_sz

Audio Element Buffer size

int out_rb_size

Size of output ringbuffer

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

bool extern_stack

At present, task stack can only be placed on SRAM, so it should always be set to false

struct embed_item_info

Embed tone information in flash.

Public Members

const uint8_t *address

The corresponding address in flash

int size

Size of corresponding data

Macros

EMBED_FLASH_STREAM_BUF_SIZE
EMBED_FLASH_STREAM_TASK_STACK
EMBED_FLASH_STREAM_TASK_CORE
EMBED_FLASH_STREAM_TASK_PRIO
EMBED_FLASH_STREAM_RINGBUFFER_SIZE
EMBED_FLASH_STREAM_EXT_STACK
EMBED_FLASH_STREAM_CFG_DEFAULT()

Type Definitions

typedef struct embed_item_info embed_item_info_t

Embed tone information in flash.

语音合成流

语音合成流 (TTS stream) 获取 esp-sresp_tts_voice 数据,只支持 AUDIO_STREAM_READER 类型。

应用示例

Header File

Functions

audio_element_handle_t tts_stream_init(tts_stream_cfg_t *config)

Create a handle to an Audio Element to stream data from TTS to another Element, the stream type only support AUDIO_STREAM_READER for now.

Return

The Audio Element handle

Parameters
  • config: The configuration

esp_err_t tts_stream_set_strings(audio_element_handle_t el, const char *strings)

Set tts stream strings.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] el: The audio element handle

  • [in] strings: The string pointer

esp_err_t tts_stream_set_speed(audio_element_handle_t el, tts_voice_speed_t speed)

Setting tts stream voice speed.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] el: The esp_audio instance

  • [in] speed: Speed will be set. 0-5 is legal. 0 is the slowest speed.

esp_err_t tts_stream_get_speed(audio_element_handle_t el, tts_voice_speed_t *speed)

Get tts stream voice speed.

Return

  • ESP_OK

  • ESP_FAIL

Parameters
  • [in] el: The esp_audio instance

  • [in] speed: Return tts stream Speed will be [0,5]

Structures

struct tts_stream_cfg_t

TTS Stream configurations, if any entry is zero then the configuration will be set to default values.

Public Members

audio_stream_type_t type

Stream type

int buf_sz

Audio Element Buffer size

int out_rb_size

Size of output ringbuffer

int task_stack

Task stack size

int task_core

Task running in core (0 or 1)

int task_prio

Task priority (based on freeRTOS priority)

bool ext_stack

Allocate stack on extern ram

Macros

TTS_STREAM_BUF_SIZE
TTS_STREAM_TASK_STACK
TTS_STREAM_TASK_CORE
TTS_STREAM_TASK_PRIO
TTS_STREAM_RINGBUFFER_SIZE
TTS_STREAM_CFG_DEFAULT()

Enumerations

enum tts_voice_speed_t

Values:

TTS_VOICE_SPEED_0
TTS_VOICE_SPEED_1
TTS_VOICE_SPEED_2
TTS_VOICE_SPEED_3
TTS_VOICE_SPEED_4
TTS_VOICE_SPEED_5
TTS_VOICE_SPEED_MAX