Trying to fetch buffer from microphone
Posted: Wed Jul 20, 2022 9:33 am
Hi,
I am trying to simply get audio buffer after 20 MS and send that buffer to other methods of the project. Examples are too complicated for such simple use case. Can you anyone guide me whether I am doing it right?
In above method is not getting called where I am supposed to be having raw data buffer which I can share with other parts of project.
Please help me.
I am trying to simply get audio buffer after 20 MS and send that buffer to other methods of the project. Examples are too complicated for such simple use case. Can you anyone guide me whether I am doing it right?
Code: Select all
DLOGD("[1.0] Start codec chip");
audio_board_handle_t board_handle = audio_board_init();
audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START);
audio_hal_set_volume(board_handle->audio_hal, 100);
DLOGD( "[2.0] Create i2s stream to read audio data from codec chip");
i2s_stream_cfg_t i2sr_cfg = I2S_STREAM_CFG_DEFAULT();
i2sr_cfg.type = AUDIO_STREAM_READER;
obj->i2s_stream_reader = i2s_stream_init(&i2sr_cfg);
DLOGD( "[3.0] Init Element");
audio_element_cfg_t cfg = DEFAULT_AUDIO_ELEMENT_CONFIG();
cfg.open = el_open;
cfg.process = el_process;
cfg.read = micstream;
cfg.tag = "my_el";
obj->raw_stream_reader = audio_element_init(&cfg);
DLOGD( "[4.0] Create pipeline");
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
obj->pipeline = audio_pipeline_init(&pipeline_cfg);
mem_assert(obj->pipeline);
ESP_LOGI(TAG, "[ 5 ] Set up event listener");
audio_event_iface_cfg_t evt_cfg = AUDIO_EVENT_IFACE_DEFAULT_CFG();
obj->evt = audio_event_iface_init(&evt_cfg);
ESP_LOGI(TAG, "[5.1] Listening event from all elements of pipeline");
audio_pipeline_set_listener(obj->pipeline, obj->evt);
audio_pipeline_register(obj->pipeline, obj->raw_stream_reader, "my_el");
audio_pipeline_register(obj->pipeline, obj->i2s_stream_reader, "i2sr");
const char *link_tag[3] = {"i2sr", "my_el"};
audio_pipeline_link(obj->pipeline, link_tag, 2);
audio_pipeline_run(obj->pipeline);
Code: Select all
read
Please help me.