convert mp3 to wav

15 views (last 30 days)
Mohamed Amine Messaoudi
Mohamed Amine Messaoudi on 11 Feb 2018
Edited: Walter Roberson on 13 Jun 2021
Hi,
I know that my question has already been asked but my problem is different
I created an Arduino Audio Player that plays wav files from SD through speaker
I want to programatically convert mp3 files to wav using the following settings :
Bit resolution : 8bit
Sampling rate : 16000Hz
Audio channels : mono
PCM format : unsigned 8 bit.
I can easily convert mp3 files using this website
However my internet is pretty slow to upload so I'm intending to do this in Matlab
I created a script that will loop through the mp3 files and convert each one of them
folder = 'C:\Users\Test\Documents\Audio\mp3'; % folder containing mp3 files
files = dir( fullfile(folder,'*.mp3') ); % list of mp3 files in folder
files = {files.name}'; % list of the files (file names)
for i=1:numel(files) % loop through each file
fname = fullfile(dirName,files{i}); % fullname of the file
mp3=audioread(fname);
newfile=strrep(fname,'mp3','wav');
wavwrite(mp3,16000,8,newfile);
end
The files are not correcltly converted and the wav file is full of noise I also get the following warning :
Warning: Data clipped during write to file:song1.wav
> In wavwrite>PCM_Quantize at 280
In wavwrite>write_wavedat at 302
In wavwrite at 139
In convert at 13
Thanks in Advance
  2 Comments
Walter Roberson
Walter Roberson on 11 Feb 2018
Which MATLAB release are you using? You are not using one of the newest versions: we can tell because wavewrite() no longer exists. But some of the details of what you need to do changed during the releases during which wavewrite did exist.
Mohamed Amine Messaoudi
Mohamed Amine Messaoudi on 11 Feb 2018
Thanks
I'm using Matlab R2013a
I know what I am doing something wrong.
When I searched I found that for 16 bit precision the values are limited to –1.0 <= y < +1.0 when the signal is provided as floating point format
But I have no idea about the changes I have to make

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 11 Feb 2018
Use audiowrite() . It is defined in R2013a https://www.mathworks.com/help/releases/R2013a/matlab/ref/audiowrite.html and permits -1.0 ≤ y ≤ +1.0

da he
da he on 20 Apr 2019
Edited: Walter Roberson on 13 Jun 2021
The follwing procedures was revised based on Mohamed Amine Messaoudi,which can succes run in matlab2019a
%conver MP3 to wav
folder = 'E:\DL_denoise\clips'; % folder containing mp3 files
files = dir( fullfile(folder,'*.mp3') ); % list of mp3 files in folder
files = {files.name}'; % list of the files (file names)
L=length(files) ;
for i=1:L
[y,Fs]=audioread(files{i});
str1=files{i};
filename=strcat(str1(1:end-3),'wav');
audiowrite(filename,y,Fs); %转写成.wav格式文件 convert to wav
end

Aayush Gupta
Aayush Gupta on 13 Jun 2021
[Y fs]= audioread(file);
audiowrite('ConvertAudioFile.wav',Y,fs)

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!