convert mp3 to wav

33 ビュー (過去 30 日間)
Mohamed Amine Messaoudi
Mohamed Amine Messaoudi 2018 年 2 月 11 日
編集済み: Walter Roberson 2021 年 6 月 13 日
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
Mohamed Amine Messaoudi 2018 年 2 月 11 日
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 Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by