:link_to_translation:zh_CN:[中文]
The Audio Stream refers to an Audio Element <../framework/audio_element>
that is responsible for acquiring of audio data and then sending the data out after processing.
The following stream types are supported:
Each stream is initialized with a structure as an input, and the returned audio_element_handle_t
handle is used to call the functions in audio_element.h
. Most streams have two types, AUDIO_STREAM_READER
(reader) and AUDIO_STREAM_WRITER
(writer). For example, to set the I2S stream type, use :cppi2s_stream_init
and :cppi2s_stream_cfg_t
.
See description below for the API details.
The algorithm stream integrates front-end algorithms such as acoustic echo cancellation (AEC), automatic gain control (AGC), and noise suppression (NS) to process the received audio. It is often used in audio preprocessing scenarios, including VoIP, speech recognition, and keyword wake-up. The stream calls esp-sr
and thus occupies large memory. The stream only supports the AUDIO_STREAM_READER
type.
- :example_file:`advanced_examples/algorithm/main/algorithm_examples.c`
- :example_file:`protocols/voip/main/voip_app.c`
The FatFs stream reads and writes data from FatFs. It has two types: "reader" and "writer". The type is defined by :cppaudio_stream_type_t
.
- Reader example:
player/pipeline_play_sdcard_music
- Writer example:
recorder/pipeline_recording_to_sdcard
The HTTP stream obtains and sends data through :cppesp_http_client
. The stream has two types: "reader" and "writer", and the type is defined by :cppaudio_stream_type_t
. AUDIO_STREAM_READER
supports HTTP, HTTPS, HTTP Live Stream, and other protocols. Make sure the network is connected before using the stream.
- Reader example
player/pipeline_living_stream
player/pipeline_http_mp3
- Writer example
recorder/pipeline_raw_http
The I2S stream receives and transmits audio data through the chip's I2S, PDM, ADC, and DAC interfaces. To use the ADC and DAC functions, the chip needs to define SOC_I2S_SUPPORTS_ADC_DAC
. The stream integrates automatic level control (ALC) to adjust volume, multi-channel output, and sending audio data with extended bit width. The relevant control bits are defined in :cppi2s_stream_cfg_t
.
- Reader example:
recorder/pipeline_wav_amr_sdcard
- Writer example:
get-started/play_mp3_control
In some cost-sensitive scenarios, the audio signal is not converted by the DAC but is modulated by the PWM (pulse width modulation) and then implemented by a filter circuit. The PWM stream modulates the audio signal with the chip's PWM and sends out the processed audio. It only has the AUDIO_STREAM_WRITER
type. Note that the digital-to-analog conversion by PWM has a lower signal-to-noise ratio.
- Writer example:
player/pipeline_play_mp3_with_dac_or_pwm
The raw stream is used to obtain the output data of the previous element of the connection or to provide the data for the next element of the connection. It does not create a thread. For AUDIO_STREAM_READER
, the connection is [i2s] -> [filter] -> [raw] or [i2s] -> [codec-amr] -> [raw]. For AUDIO_STREAM_WRITER
, the connection is [raw] ->[codec-mp3]->[i2s].
- Reader example:
protocols/voip
- Writer example:
advanced_examples/downmix_pipeline
The SPIFFS stream reads and writes audio data from or into SPIFFS.
player/pipeline_spiffs_mp3
The TCP client stream reads and writes server data over TCP.
get-started/pipeline_tcp_client
The tone stream reads the data generated by :adf_file:`tools/audio_tone/mk_audio_tone.py. It only supports the AUDIO_STREAM_READER` type.
player/pipeline_flash_tone
The flash-embedding stream reads the data generated by :adf_file:`tools/audio_tone/mk_embed_flash.py. It only supports the AUDIO_STREAM_READER` type.
player/pipeline_embed_flash_tone
The tex-to-speech stream (TTS stream) obtains the esp_tts_voice
data of esp-sr
. It only supports the AUDIO_STREAM_READER
type.
- Reader example:
player/pipeline_tts_stream