espressif / esp-adf

Espressif Audio Development Framework
Other
1.49k stars 667 forks source link

pipeline_raw_http录音如何将wav格式换成mp3格式 (AUD-5253) #1163

Open liuliuu-112 opened 4 months ago

liuliuu-112 commented 4 months ago

目前使用这个例程想将wav格式转换成mp3格式,减少数据量来解决防止网络不好造成的录音上传不到服务器的问题

TempoTian commented 4 months ago

可以参考例子 https://github.com/espressif/esp-adf/blob/master/examples/recorder/pipeline_recording_to_sdcard/main/recording_to_sdcard_example.c#L213

目前mp3 encoder是不支持的,不过你可以编码为 AAC 或者 AMR 都可以,对应的 server 部分也要改动下,直接存储收到的数据就可以了 参考代码如下:

    aac_encoder_cfg_t aac_cfg = DEFAULT_AAC_ENCODER_CONFIG();
    aac_cfg.sample_rate = i2s_cfg.i2s_cfg.sample_rate;
    aac_cfg.channel= EXAMPLE_AUDIO_CHANNELS;
    audio_element_handle_t aac_enc = aac_encoder_init(aac_encoder_cfg_t *config);

    ESP_LOGI(TAG, "[3.3] Register all elements to audio pipeline");
    audio_pipeline_register(pipeline, i2s_stream_reader, "i2s");
    audio_pipeline_register(pipeline, http_stream_writer, "http");
    audio_pipeline_register(pipeline, aac_enc, "aac_enc");

    ESP_LOGI(TAG, "[3.4] Link it together [codec_chip]-->i2s_stream->http_stream-->[http_server]");
    const char *link_tag[2] = {"i2s", "http", "aac_enc"};
    audio_pipeline_link(pipeline, &link_tag[0], 3);