简体   繁体   English

使用Ruby,PHP或Python进行音频水印

[英]Audio watermarking with Ruby, PHP or Python

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. 首先,文件需要转换为.WAV格式。
  • Secondly, depending on their length, I need to insert a short audible watermark at certain intervals in each of the new .WAV files. 其次,根据它们的长度,我需要在每个新的.WAV文件中的特定间隔处插入一个简短的可听水印。

The first part is easy, using the LAME encoder cli. 第一部分很简单,使用LAME编码器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. 第二部分是很难解决的问题-我已经尝试了LAME和FFmpeg的一些方法,但似乎无法使其工作。

The script is running as a cron job in the background, so full cli access is available. 该脚本在后台作为cron作业运行,因此可以使用完整的cli访问。

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. 如果可能的话,如果有人可以将我指向示例脚本/ gem或以某种相关方式执行此操作的类,那就太好了。

This gets complicated. 这变得复杂。 You need to actually mix the audio, which to my knowledge, isn't possible with FFMPEG. 据我所知,您实际上需要混合音频,而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. 您将遇到的另一个问题是,如果您携带MP3并将其转换为WAV,以便可以使用它,然后将其重新编码回MP3,则质量会下降。

I think you can use Sox for this: http://sox.sourceforge.net/ 我认为您可以为此使用Sox: http//sox.sourceforge.net/

Use FFMPEG first to decode the audio to WAV, adjusting sample rate and bit depth as necessary. 首先使用FFMPEG将音频解码为WAV,并根据需要调整采样率和位深度。

Then, call out to soxmix : http://linux.die.net/man/1/soxmix 然后,调出至soxmixhttp : soxmix

If you're ready to take the Python route, I would suggest SciPy , which can read WAV files into NumPy arrays: 如果您准备采用Python路线,建议使用SciPy ,它可以将WAV文件读取到NumPy数组中:

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

(the official documentation contains details). 官方文档中包含详细信息)。

Sounds can be conveniently manipulated through the array manipulation routines of NumPy . 可以通过NumPy的数组操作例程方便地操作声音。

scipy.io.wavfile can then write the file back to the WAV format. scipy.io.wavfile然后可以将文件写回WAV格式。

SciPy and NumPy are general scientific data tools. SciPy和NumPy是通用的科学数据工具。 More music-centric Python modules can be found on the official web site. 在官方网站上可以找到更多以音乐为中心的Python模块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM