Read and compare multiple audio files

조회 수: 18 (최근 30일)
MATTHEW JONES
MATTHEW JONES 2021년 2월 19일
편집: jibrahim 2021년 2월 24일
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:
  1. Read an audio file
  2. See if my sample is from current audio file
  3. If it is I need the file number (out of 39), as well as where in the file my sample is from
  4. If not I need to move on to the next file
Any help with this would be greatly appreciated

답변 (1개)

jibrahim
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

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by