I would like to get help in a code. Problem: I would like to randomly select five audio files in a directory which are wav files. The directory contains three thousand audio files all wav format. I should be able to insert first audio files then I have another wav file which is 1.5 seconds silence, then I should be able to randomly select another wav file from the directory. Then I should be able to randomly concatenate another audio file and then 1.5 sec silence audio file. Since I need to insert five audio files based on random selection, I should insert four 1.5 sec silence audios to get my first audio file ready. The process is like creating an audio captcha where different characters are being spoken and we need to concatenate those characters with silence in between those characters. I have all the required audio files processed and ready. Just need help in coding this part. Many Thanks!

 Réponse acceptée

KSSV
KSSV le 25 Jan 2021
N = 10 ;
C = cell(N,1) ;
% C(2:2:end) = insert your silence audio
idx = 1:2:N ; % left indices to insert your required qudio files out of 1000
n = 1000 ; % these many audio files present
iwant = randperm(n,length(idx)) ; % select five audio files randomly out of 1000
C{idx(1)} = iwant(1) ; % insert audio files
C{idx(2)} = iwant(2) ;
% insert all five
C = cell2mat(C{:}) ; % convert them into array

5 commentaires

Fareed Jamali
Fareed Jamali le 25 Jan 2021
The audios are in a separate folder and the silence audio is in the directory where the script is supposed to be saved. Can you please suggest the changes based on this? I have three thousand different audio files in the directory. Thank you!
Fareed Jamali
Fareed Jamali le 25 Jan 2021
Here is the current folder
KSSV
KSSV le 25 Jan 2021
You can access the files present in the folder using dir. Read about it.
clear all
close all
clc
folder='C:\Users\Fareed Jamali\Desktop\Audio_Dataset\matlab\recordings_after_amplification';
audio_files=dir(fullfile(folder,'*.wav'))
%How many times do we need the loop to execute
N=10;
C=cell(N,1);
C(2:2:end)=('Silent.wav');
idx=1:2:N;
n=1000;
iwant=randperm(n,length(idx));
C{idx(1)}=iwant(1);
C{idx(2)}=iwant(2);
C=cell2mat(C{:});
n = length(audio_files) ;
iwant=randperm(n,length(idx));
for i = 1:length(idx)
thisFile = audio_files{iwant(i)} ;
% C{idx(i)} = save here
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Audio I/O and Waveform Generation dans Centre d'aide et File Exchange

Produits

Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by