looping in all audio files

9 ビュー (過去 30 日間)
Abdullah Mogazi
Abdullah Mogazi 2022 年 8 月 16 日
回答済み: jibrahim 2022 年 8 月 18 日
I'm trying to remove silence in audio files I already did that in every single file but I still have thousand of another files. but to save time, how I can loop them to silence all files in the same time and be able to download all new audios?. I tried but it gets me some errors.
clc; clear all; [filenames, pathname] = uigetfile({'.wav'},'Select file .wav', ... 'MultiSelect', 'on'); fullpathnames = fullfile(pathname, cellstr(filenames)); numfiles = length(fullpathnames); audio = cell(numfiles, 1); fs = zeros(numfiles, 1); for i = 1: numfiles
[audio{i}, fs(i)] = audioread(fullpathnames{i}); end % do framing f_d = 0.25; f_size = round(f_d
fs); n = length(audio); n_f = floor(n/f_size); %no. of frames temp = 0; for i = 1 : n_f
frames(i,:) = audio(temp + 1 : temp + f_size); temp = temp + f_size; end % silence removal based on max amplitude m_amp = abs(max(frames,[],2)); % find maximum of each frame id = find(m_amp > 0.03); % finding ID of frames with max amp > 0.03 fr_ws = frames(id,:); % frames without silence % reconstruct signal audio_r = reshape(fr_ws',1,[]); plot(audio_r); title('speech without silence'); hold on; plot(audio,'r'); legend('After Silence Removal','Original Signal'); frame_analysis_silence_removal.m Displaying frame_analysis_silence_removal.m.

回答 (2 件)

Benjamin Thompson
Benjamin Thompson 2022 年 8 月 16 日
dir('*.wav') will return a struct containing all the audio file names. Then you can pass the name field of each element of that structure array to audioread in a for loop. That would take uigetfile out of the picture.
  3 件のコメント
Walter Roberson
Walter Roberson 2022 年 8 月 16 日
編集済み: Walter Roberson 2022 年 8 月 17 日
You should format your code first before expecting someone to edit it. With the way it is now, we cannot tell where the comments end.
Benjamin Thompson
Benjamin Thompson 2022 年 8 月 17 日
Here is a small sample to try yourself and if you have problems and want to post a new sample of your code for help, you may do that.
>> cd rtwdemo_roll_ert_rtw\
>> D = dir('*.c')
D =
2×1 struct array with fields:
name
folder
date
bytes
isdir
datenum
>> D(1).name
ans =
'ert_main.c'
>> D(2).name
ans =
'rtwdemo_roll.c'

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


jibrahim
jibrahim 2022 年 8 月 18 日
audioDatastore can simplify this type of task.
ads = audioDatastore(yourFolder);
% Read all files, one by one, using a while-loop
while hasdata(ads)
[data,info] = read(ads);
% do whatever you want with the data
end

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by