Audio watermarks with Ruby, PHP or Python

I am working on a project where I need to post a bunch of audio files in various formats.

  • First, the files must be converted to the .WAV format.
  • Secondly, depending on their length, I need to insert a short sound watermark at regular intervals in each of the new .WAV files.

The first part is simple using the LAME cli encoder. the second part is where it gets difficult - I tried several methods with LAME and FFmpeg, but I can't get it to work.

The script works like a cron job in the background, so full access to cli is available.

If possible, it would be great if someone could give me an example script / gem or class that does this in some way.

+4
source share
2 answers

This is getting complicated. You really need to mix audio, which, as far as I know, is not possible with FFMPEG. Another problem you have to deal with is the loss of quality if you take MP3s, convert it to WAV so that you can work with it, and transcode it back to MP3.

I think you can use Sox for this: http://sox.sourceforge.net/

First use FFMPEG to decode the audio in WAV, adjusting the sample rate and bit depth if necessary.

Then call soxmix : http://linux.die.net/man/1/soxmix

+1
source

If you are ready to take the Python route, I would suggest SciPy , which can read WAV files in NumPy arrays:

 from scipy.io import wavfile fs, data = wavfile.read(filename) 

(official documentation contains detailed information).

Sounds can be conveniently manipulated using NumPy array manipulation procedures.

scipy.io.wavfile can then write the file back to the WAV format.

SciPy and NumPy are common scientific data tools. More music-oriented Python modules can be found on the official website.

+1
source

All Articles