Use DTW to Compare Recordings
Import, trim, and preprocess four recordings of the first sentence of Alice in Wonderland.
show complete Wolfram Language input
In[2]:=
![Click for copyable input](assets.en/use-dtw-to-compare-recordings/In_58.png)
alice = ConformAudio[
MapThread[
AudioNormalize[
AudioChannelMix[AudioTrim[AudioResample[Import[#1], 11025], #2],
1]] &, {urls, times}]]
Out[2]=
![](assets.en/use-dtw-to-compare-recordings/O_25.png)
Show the plots for the signals.
In[3]:=
![Click for copyable input](assets.en/use-dtw-to-compare-recordings/In_59.png)
AudioPlot[alice, ImageSize -> Medium]
Out[3]=
![](assets.en/use-dtw-to-compare-recordings/O_26.png)
Compute and plot the MFCC features for the samples.
In[4]:=
![Click for copyable input](assets.en/use-dtw-to-compare-recordings/In_60.png)
mfcc = AudioLocalMeasurements[#, "MFCC",
PartitionGranularity -> {.05, .01}]["Values"] & /@ alice;
In[5]:=
![Click for copyable input](assets.en/use-dtw-to-compare-recordings/In_61.png)
Column[MatrixPlot[#, PlotTheme -> "Minimal", ImageSize -> Medium] & /@
Transpose /@ mfcc]
Out[5]=
![](assets.en/use-dtw-to-compare-recordings/O_27.png)
Compute the dynamic time warping distance between the recordings using WarpingDistance.
In[6]:=
![Click for copyable input](assets.en/use-dtw-to-compare-recordings/In_62.png)
DistanceMatrix[mfcc,
DistanceFunction -> WarpingDistance] // MatrixPlot
Out[6]=
![](assets.en/use-dtw-to-compare-recordings/O_28.png)
Compute the dynamic time warping correspondence between two of the recordings using WarpingCorrespondence.
In[7]:=
![Click for copyable input](assets.en/use-dtw-to-compare-recordings/In_63.png)
{n, m} = WarpingCorrespondence[mfcc[[1]], mfcc[[2]]];
show complete Wolfram Language input
Out[8]=
![](assets.en/use-dtw-to-compare-recordings/O_29.png)