Ajouter 'wav_convert.m'

This commit is contained in:
Rémi BUSSIERE 2023-07-19 16:01:13 +02:00
parent a1062222df
commit e7f67d8e30
1 changed files with 42 additions and 0 deletions

42
wav_convert.m Normal file
View File

@ -0,0 +1,42 @@
pkg load signal
file_path = 'signaluk.wav';
[x, Fs] = audioread(file_path);
t = (0:length(x)-1) / Fs;
% Assuming you have already loaded the audio signal 'y' and the sampling rate 'Fs'
% Calculate the total duration of the signal in seconds
total_duration = length(y) / Fs;
% Define the time points for splitting the signal
start_time_part1 = 1.0; % Start time for the first part (in seconds)
end_time_part1 = start_time_part1 + 1.0; % End time for the first part (in seconds)
% Find the indices corresponding to the desired time range for part 1
start_index_part1 = floor(start_time_part1 * Fs) + 1;
end_index_part1 = floor(end_time_part1 * Fs);
% Split the signal into part 1
part1_signal = y(start_index_part1:end_index_part1);
% Calculate the time points for part 2
start_time_part2 = end_time_part1; % Start time for the second part (in seconds)
end_time_part2 = total_duration; % End time for the second part (in seconds)
% Find the indices corresponding to the desired time range for part 2
start_index_part2 = floor(start_time_part2 * Fs) + 1;
end_index_part2 = floor(end_time_part2 * Fs);
% Split the signal into part 2
part2_signal = y(start_index_part2:end_index_part2);
% Save the two parts as separate WAV files
filename = 'part1.wav';
audiowrite(char(filename), part1_signal, Fs);
filename = 'part2.wav';
audiowrite(char(filename), part2_signal, Fs);