简体   繁体   English

如何使用php将音频消息嵌入音频文件?

[英]How to embed audio message into an audio file with php?

I would like know if it is possible to create embedding of audio message to audio files? 我想知道是否可以将音频消息嵌入音频文件吗?

For example, on playing every 10 sec of an audio, it would be interrupted with an audio message "You are currently listening to an audio by XYZ band" and then the audio continues. 例如,每隔10秒钟播放一次音频,就会被一条音频消息“您当前正在按XYZ频段收听音频”打断,然后继续播放音频。 And even if someone were to download the mp3 file, the audio message is still embedded with that downloaded file? 即使有人要下载mp3文件,音频消息是否仍与该下载文件一起嵌入?

May I know if there are any libraries or classes that can work with php to achieve the above result? 我可以知道是否有任何可与php配合使用的库或类来实现上述结果吗? And what would be the workflow? 那工作流程是什么?

Thank you very much. 非常感谢你。

You definitely can't do that in pure PHP - in theory you could write a MP3 decoding and encoding engine for PHP but it's an insane idea - and you will need some server side help for the task. 您绝对不能在纯PHP中做到这一点-从理论上讲,您可以为PHP编写MP3解码和编码引擎,但这是一个疯狂的想法-并且您将需要一些服务器端帮助来完成此任务。

ffmpeg should enable you to mix multiple MP3s together to one file, provided your host supports it. ffmpeg应该使您能够将多个MP3混合到一个文件中,前提是您的主机支持它。

I would use sox for everything. 我会为一切使用袜。 It can decode and chop up the audio into segments, into which you can interject your message, and then render the sequence into a new mp3 file. 它可以将音频解码并切成片段,您可以在其中插入消息,然后将序列渲染到新的mp3文件中。 It should also be able to overlay the messages onto the audio, so you don't break up the music, which might sound more pleasant. 它还应该能够将消息覆盖在音频上,这样您就不会破坏音乐,这听起来会更令人愉悦。

Of course, this means using PHP just for management. 当然,这意味着仅将PHP用于管理。 The signal processing would be done by sox. 信号处理将通过sox完成。 If you really want to do as much as possible in PHP, use an external tool to decode the mp3 into a wave file, load the PCM into an integer array in PHP, and manipulate it there. 如果您真的想在PHP中做尽可能多的事情,请使用外部工具将mp3解码为wave文件,将PCM加载到PHP中的整数数组中,然后在其中进行操作。 PHP is probably not very fast when it comes to number crunching like this, but it should be possible. 当像这样处理数字时,PHP可能不是很快。但是应该可以。 Save the PCM to disk for final encoding. 将PCM保存到磁盘以进行最终编码。

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

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