Clear Filters
Clear Filters

Need Help in importing Audio files

3 views (last 30 days)
Satyam Gaba
Satyam Gaba on 3 Apr 2018
Answered: Dinesh Iyer on 27 Apr 2018
Hi, I want to import 50 audio files with name as "s1,s2,...s50" and train them for speaker recognition purpose.
if true
[training_data1,fs_training1]=audioread('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\S1.wav');
[training_data2,fs_training2]=audioread('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\S2.wav');
[training_data3,fs_training3]=audioread('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\S3.wav');
[training_data4,fs_training4]=audioread('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\S4.wav');
[training_data5,fs_training5]=audioread('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\S5.wav');
[training_data6,fs_training6]=audioread('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\S6.wav');
[training_data7,fs_training7]=audioread('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\S7.wav');
[training_data8,fs_training8]=audioread('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\S8.wav');
end
something like this.
how can I use loop, "like for or while" in this process? TIA

Answers (1)

Dinesh Iyer
Dinesh Iyer on 27 Apr 2018
You can use the FileDataStore object and supply audioread as the custom read function. This will save you the hassle of looping:
fds = fileDatastore('C:\Users\Satyam\Documents\MATLAB\SOP\data\train\','ReadFcn',@audioread, 'FileExtensions', '.wav');
while hasdata(fds)
[y, Fs] = read(fds);
end
See the documentation for this function here: https://www.mathworks.com/help/matlab/ref/matlab.io.datastore.filedatastore.html

Community Treasure Hunt

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

Start Hunting!