Read and compare multiple audio files
조회 수: 6 (최근 30일)
이전 댓글 표시
I'm trying to write a function that can match a ten second audio sample to the audio file that it came from, out of 39 audio files. I need to search through a directory of audio files to find the file that my sample came from. I know I need to use the xcorr function in some way but I can't figure out how to read through the directory to make the comparison.
Basicaly I need to:
- Read an audio file
- See if my sample is from current audio file
- If it is I need the file number (out of 39), as well as where in the file my sample is from
- If not I need to move on to the next file
Any help with this would be greatly appreciated
댓글 수: 0
답변 (1개)
jibrahim
2021년 2월 24일
편집: jibrahim
2021년 2월 24일
% Use an audioDatastore to point to all audio files in a folder
% Set IncludeSubFolders to true to read subfolders too
ads = audioDatastore(pwd,'IncludeSubfolders',true);
% Read the first 5 seconds of a file of your choice
% This is example code - change it to your use case
index = 39;
[sig,Fs] = audioread(ads.Files{39});
sig = sig(1:Fs*5);
% Read all the files
% If you have too many files, and the signals don't all fit in memory, use
% a for loop instead (use read(ads) to read the datastore one file at a
% time)
allData = readall(ads);
% Find the max correlation of each signal with sig
m = cellfun(@(x)max(xcorr(x, sig)), allData, 'UniformOutput', false);
% Pick the index of max of max value
[~,index2] = max(cell2mat(m));
fprintf('Actual: %d\n',index) %39
fprintf('Expected: %d\n',index2) %39
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!