chrisstaite / lameenc

Python bindings around the LAME encoder
GNU Lesser General Public License v3.0
51 stars 8 forks source link

Expose resample parameter from LAME? #26

Closed armandobelardo closed 11 months ago

armandobelardo commented 11 months ago

Hi there @chrisstaite! Thank you for all the work put into this library! I was wondering if you'd be open to a PR that exposes the --resample flag? I have some audio I need to have converted from WAV to 32kbps bit rate and a 44.1khz sample rate mp3 and as is, with the code below LAME is automatically resampling the audio to a lower sample rate (22.05khz)

From some documentation, it looks as though this is expected and you have to resample the audio in LAME to get the desired output sample rate:

If not specified, LAME may sometimes resample automatically when faced with extreme compression conditions (like encoding a 44.1 kHz input file at 32 kbps). To disable this automatic resampling, you have to use --resample to set the output samplerate equal to the input samplerate. In that case, LAME will not perform any extra computations.

encoder = lameenc.Encoder()
encoder.set_bit_rate(32)
encoder.set_in_sample_rate(44100)
encoder.set_channels(1)
encoder.set_quality(2)
chrisstaite commented 11 months ago

Hi, always accepting of PRs. I prefer not to break compatibility, but that's really the only constraint.

Seems like it's a trivial copy-paste of set_in_sample_rate to expose lame_set_out_samplerate.