-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_silent_wav_files.m
60 lines (49 loc) · 1.95 KB
/
delete_silent_wav_files.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function delete_silent_wav_files(folder_path)
% Set silence threshold
silence_threshold = 1e-7;
% Get all .wav files in the specified folder
file_list = dir(fullfile(folder_path, '*.wav'));
% Initialize progress bar
waitbar_h = waitbar(0, 'Processing files...');
% Initialize counters
total_files = length(file_list);
processed_count = 0;
deleted_count = 0;
error_count = 0;
% Process each file
for i = 1:total_files
file_path = fullfile(folder_path, file_list(i).name);
try
% Read WAV file
[y, fs] = audioread(file_path);
% DC center the signal
y_centered = y - mean(y);
% Calculate RMS of the centered signal
rms_level = sqrt(mean(y_centered.^2));
% Check if the file is silent based on RMS threshold
if rms_level < silence_threshold
% Delete the file
delete(file_path);
fprintf('Deleted silent file: %s (RMS: %.9f)\n', file_list(i).name, rms_level);
deleted_count = deleted_count + 1;
else
fprintf('Kept non-silent file: %s (RMS: %.9f)\n', file_list(i).name, rms_level);
end
processed_count = processed_count + 1;
catch ME
warning('Error processing file %s: %s', file_list(i).name, ME.message);
error_count = error_count + 1;
end
% Update progress bar
waitbar(i / total_files, waitbar_h);
end
% Close progress bar
close(waitbar_h);
% Print summary
fprintf('\nProcessing complete.\n');
fprintf('Total files: %d\n', total_files);
fprintf('Processed: %d\n', processed_count);
fprintf('Deleted (silent): %d\n', deleted_count);
fprintf('Kept (non-silent): %d\n', processed_count - deleted_count);
fprintf('Errors: %d\n', error_count);
end