How many audio samples per second — and why it controls both quality and file size
Sample rate is how many times per second the audio is measured and stored as a number. At 44100 Hz, the audio is captured 44,100 times every second. Each of those measurements is one 16-bit integer in your clip.h array.
More samples per second = higher quality = larger file. Fewer samples = smaller file = lower quality. The trick is finding the lowest rate that still sounds good for what you need.
| Sample rate | Size per second | Good for |
|---|---|---|
| 44100 Hz | ~88 KB | Music, anything that needs to sound great |
| 22050 Hz | ~44 KB | Speech, sound effects - half the size, still clear |
| 16000 Hz | ~32 KB | Voice only - nearly triple capacity, fully intelligible |
The sample rate in your sketch and the rate you converted the audio to with ffmpeg must be the same number. If they do not match, the audio will play back at the wrong speed and wrong pitch.
In the sketch:
#define SAMPLE_RATE 22050 In the ffmpeg conversion command:
ffmpeg -y -i /tmp/myclip.wav -ar 22050 -ac 1 -acodec pcm_s16le /tmp/clip_i2s.wav Change both together and they will always stay in sync.