Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert audio files in PHP

I need to convert AMR audio file to MP3. How can I make it in PHP without FFMPEG (i have no permissions to install it on the server). Please help me.

like image 228
Alex Pliutau Avatar asked Dec 02 '22 01:12

Alex Pliutau


2 Answers

Use SoX - the Swiss Army knife of sound processing. Very easy to use.

It is a command line tool not a PHP library so to use from PHP you need to execute a shell command and get the result with in your code. I have used it with in few projects.

Example with PHP:

<?php
exec('sox /mypath/my_audio.amr /mypath/my_audio.mp3');
?>

SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files, and, as an added bonus, SoX can play and record audio files on most platforms.

SoX is very mature project! Here is the link: http://sox.sourceforge.net/

Here are some examples I googled for you: http://www.thegeekstuff.com/2009/05/sound-exchange-sox-15-examples-to-manipulate-audio-files/

like image 176
Ivelin Avatar answered Dec 18 '22 11:12

Ivelin


Just use ffmpeg. You can simply download a binary of ffmpeg (look for "static builds"), and then point your script to the binary. There is no need to install it so there should be no permission issues.

like image 32
llogan Avatar answered Dec 18 '22 12:12

llogan