Ive been trying to interface with the lame_enc.dll using Python ctypes, and encode wav to mp3. This problem was discussed in 2008 at http://www.dreamincode.net/forums/topic/72083-lame-mp3-encoder-for-python/ with no resolution.
I think that I am quite close, as I have an mp3 output in which I can hear some words recorded to wav at 22050 Hz, mono. However something is still wrong, as I also get regular click sounds in the output.
My code is at: http://pastebin.com/SFwCuZZU
Ive been using:
libmp3lame-win-3.98.2.zip windows binary from http://lame1.buanzo.com.ar/ Within the dll folder there is the BladeMP3EncDLL.h file with data structure defs, and an example.cpp which I am attempting to convert directly to python/ctypes. I have copied these to http://pastebin.com/E41nzq7m and http://pastebin.com/ySGfwhPD respectively.
Further guidance on the lame encoder dll from http://openinnowhere.sourceforge.net/lameonj/LameDLLInterface.htm
One possible problem is that the size of my beConfig data structure reported by ctypes is 332 bytes, not the expected 331 that is documented in the header file, and which I expect from a manual check. Then again it may just be the config settings.
Update: See http://pastebin.com/cdUniF1e Almost there... The second parameter of beEncodeChunk is the number of samples, not the number of bytes. Mp3 sounds good now except for one click at the beginning :-(.
Success! Its still not very pretty but it works. The assumption of a 44 byte header for wav is not always correct, which is why I had the click - it was encoding data from the wav header into the first mp3 chunk. I used the Python wave module instead to read frames (with the added benefit that the number of channels and frame rate are easily obtained.) See http://pastebin.com/ehDajzhN