Read and Write MP3 files in MATLAB, and use the ready-made mp3read and mp3write.
- Download the mp3read.m, mp3write. M, mpg123.exe, mp3info.exe, and lame.exe files at http://labrosa.ee.columbia.edu/matlab /mp3read.htmland put them in a folder named MP3.
- Put the MP3 folder in the installation directory of MATLAB ../MATLAB 71/toolbox/Matlab.
- In Matlab, add a path and choose File> set path.... In the displayed set path dialog box, select Add folder..., select the MP3 folder, save, and close.
- Modify the content of the mp3read and mp3write files:
To make them work, you also need to make small changes to the mp3read. m and mp3write. M scripts. first, you must change the location that the script looks for binaries e.g. change the lines:
%%%%%% Location of the binaries mpg123 = '/usr/bin/mpg123'; % for mp3read mp3info = '/usr/bin/mp3info'; % for mp3read lame = '/usr/bin/lame'; % for mp3write
To point to the directory where you put the binaries above, e.g.
mpg123 = 'C:/Matlab6p5/work/project/mpg123.exe'; mp3info = 'C:/Matlab6p5/work/project/mp3info.exe'; lame = 'C:/Matlab6p5/work/project/lame.exe';
Secondly, you must also change the directory where temporary files are written, and the command used to delete them, e.g .:
%%%%%% Directory for temporary file (if needed) tmpdir = '/tmp/'; %%%%%% Command to delete temporary file (if needed) rmcmd = 'rm';
.. To be a suitable directory for temporary files on your system and the appropriate command to delete them, e.g.
tmpdir = 'C:/Matlab6p5/work/project/tmp/'; % don't forget trailing slash rmcmd = 'del';
-
Done! You can run the help mp3read command in MATLAB to test whether mp3read. m can be found.
Now we can use mp3read and mp3write just like using wavread and wavwrite.