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!

 채택된 답변

KSSV
KSSV 2021년 1월 25일

0 개 추천

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

Fareed Jamali
Fareed Jamali 2021년 1월 25일
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 2021년 1월 25일
Here is the current folder
KSSV
KSSV 2021년 1월 25일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

제품

릴리스

R2019a

태그

질문:

2021년 1월 25일

댓글:

2021년 1월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by