convert mp3 to wav

17 次查看(过去 30 天)
Mohamed Amine Messaoudi
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 个评论
Walter Roberson
Walter Roberson 2018-2-11
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
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

请先登录,再进行评论。

回答(3 个)

Walter Roberson
Walter Roberson 2018-2-11
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 2019-4-20
编辑:Walter Roberson 2021-6-13
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 2021-6-13
[Y fs]= audioread(file);
audiowrite('ConvertAudioFile.wav',Y,fs)

类别

Help CenterFile Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by