2011-10-07 15:47 浏览 102


I'm working on a project where I need to post-process a bunch of audio files in various formats.

  • Firstly, the files need to be converted to .WAV format.
  • Secondly, depending on their length, I need to insert a short audible watermark at certain intervals in each of the new .WAV files.

The first part is easy, using the LAME encoder cli. The second part is where it get's difficult - I've tried a few method with both LAME and FFmpeg, but can't seem get it working.

The script is running as a cron job in the background, so full cli access is available.

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答 默认 最新

  • 已采纳
    dongshi9407 dongshi9407 2011-10-07 19:13

    This gets complicated. You need to actually mix the audio, which to my knowledge, isn't possible with FFMPEG. The other problem you're going to have is loss of quality if you take an MP3, convert it to WAV so you can work with it, and re-encode it back to MP3.

    I think you can use Sox for this:

    Use FFMPEG first to decode the audio to WAV, adjusting sample rate and bit depth as necessary.

    Then, call out to soxmix:

    点赞 评论 复制链接分享
  • dongpu1879 dongpu1879 2011-10-07 19:23

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

    from import wavfile
    fs, data =

    (the official documentation contains details).

    Sounds can be conveniently manipulated through the array manipulation routines of NumPy. can then write the file back to the WAV format.

    SciPy and NumPy are general scientific data tools. More music-centric Python modules can be found on the official web site.

    点赞 评论 复制链接分享