Reading, resampling and writing audio files

22 ビュー (過去 30 日間)
Rahul Jaiswal
Rahul Jaiswal 2017 年 8 月 3 日
コメント済み: shweta singh 2020 年 5 月 30 日
I have multiple audio files in one folder having file format like C_01_ECHO_FA.wav, C_01_ECHO_FG.wav, C_01_ECHO_MK.wav, C_01_ECHO_ML.wav and again C_02_ECHO_FA.wav, C_02_ECHO_FG.wav, C_02_ECHO_MK.wav, C_02_ECHO_ML.wav and so on like this... The sampling freq of these files are 48k. I need to read all the audio files one by one and resample them to 8k and then write all output audio files in different folder. For the single file, i did like this but i need to do for all. [y,Fs] = audioread('C_01_ECHO_FA.wav'); y_resamp = resample(y,8000,48000); audiowrite('C_01_ECHO_FA_new.wav',y_resamp,8000);

採用された回答

Deepak Gala
Deepak Gala 2017 年 8 月 4 日
This should do what you want.
[y,fs]=audioread('file48000.wav'); audiowrite('file8000.wav',y,8000);
  2 件のコメント
Rahul Jaiswal
Rahul Jaiswal 2017 年 8 月 4 日
Thank you for the answer. But i can do with the single file. I have say, 10 different files in one folder. I need to read them one by one automatically, resample each one and write those files in another folder. Mainly the problem is reading all wav files one by one from one folder automatically and writing them one by one in another folder after resampling.
Laureano Moro
Laureano Moro 2018 年 8 月 28 日
The resampling is missing in this answer. The new file 'file8000.wav' will not be resampled at 8kHz unless y = resample(y,8000,48000); is included before the use of audiowrite.

サインインしてコメントする。

その他の回答 (2 件)

Laureano Moro
Laureano Moro 2018 年 8 月 28 日
編集済み: Laureano Moro 2018 年 8 月 28 日
To do it automatically:
sAudioFolder='MyAudiofolder'; eFiles=dir(fullfile(sAudioFolder,'*.wav'));
for i=1:length(eFiles)
sAudioFile=fullfile(sAudioFolder,eFiles(i).name);
[y,Fs] = audioread(sAudioFile); y_resamp = resample(y,8000,48000);
sAudioFileOut=fullfile(sAudioFolder,[strrep(eFiles(i).name,'.wav','') '_new.wav']);
audiowrite(sAudioFileOut,y_resamp,8000);
end
  1 件のコメント
shweta singh
shweta singh 2020 年 5 月 30 日
very good code

サインインしてコメントする。


Deepak Gala
Deepak Gala 2017 年 8 月 7 日
This should work!
for i=1:1000
FILE1=sprintf('file48000_%d.wav',i);
FILE2=sprintf('file8000_%d.wav',i);
FOLDER_NAME = 'C:\.......\ReadingFolder';
userpath(FOLDER_NAME);
[y,fs]=audioread(FILE1);
FOLDER_NAME = 'C:\.......\WritingFolder';
userpath(FOLDER_NAME);
audiowrite(FILE2,y,8000);
end
  1 件のコメント
Rahul Jaiswal
Rahul Jaiswal 2017 年 8 月 8 日
Thanks dear !

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by