pschatzmann / arduino-liblame

A simple mp3 encoder (not only) for Arduino using LAME
20 stars 3 forks source link

The mp3 volume is too low to hear. #12

Closed wangzongming closed 2 hours ago

wangzongming commented 3 hours ago

🌹Hello, can you help me to see how to change the code? I want to convert pcm to mp3 and send it to the server. It worked. However, the mp3 file saved in the server cannot be heard when playing, and the sound can be heard after the volume is amplified by ffmpeg. Is there any way to amplify the volume in the following code?

loop(){ 
        i2s_read(MIC_i2s_num, (void *)diy_wakeup_sample_buffer, sizeof(diy_wakeup_sample_buffer), &diy_wakeup_bytes_read, portMAX_DELAY);
        esp_ai_mp3_encoder.write(diy_wakeup_sample_buffer, sizeof(diy_wakeup_sample_buffer));
}

I've tried the following, but it doesn't sound very effective.

i2s_read(MIC_i2s_num, (void *)diy_wakeup_sample_buffer, sizeof(diy_wakeup_sample_buffer), &diy_wakeup_bytes_read, portMAX_DELAY); 
for (size_t i = 0; i < sizeof(diy_wakeup_sample_buffer) / 2; i++) 
{ 
     diy_wakeup_sample_buffer[i] = diy_wakeup_sample_buffer[i] * 128;
}

esp_ai_mp3_encoder.write(diy_wakeup_sample_buffer, sizeof(diy_wakeup_sample_buffer));
pschatzmann commented 2 hours ago

I suggest to use the AudioTools; follow the advice given under Audio Source. This let's you decide how much you can ampltiy. You can even implement a dynamic amplification by checking the actual volume using a VolumeMeter.

wangzongming commented 2 hours ago

Thank you for your prompt reply.