Python analysis of wav files

For the analysis of sound files, in addition to listening, it is best to convert the sound into graphics, so that there is a visual perception of the difference between the sound files, which can be a very useful supplement for subsequent analysis.

Python can use SCIPY library to load wav files and use matplotlib to draw graphics. First I downloaded 1M and 2M wav files from this website as wav sample files: https://file-examples.com/index.php/sample-audio-files/sample-wav-download/

Then use the following code to install and draw the tonal graph of the wav file:

from scipy.io import wavfile
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
 
# load wav files
fs_1m,data_1m = wavfile.read("./wav/file_example_WAV_1MG.wav")
fs_2m,data_2m = wavfile.read("./wav/file_example_WAV_2MG.wav")
 
# set plt style
plt.style.use('seaborn-whitegrid')
 
# plot data
fig,(ax1, ax2)= plt.subplots(1,2)
ax1.plot(data_1m, color='b')
ax1.set_title("auido with 1M size")
ax2.plot(data_2m, color='y')
ax2.set_title("auido with 2M size")
 
plt.savefig('audio.png', dpi=150)

The output graphics are as follows:

It can be seen that the two graphics are basically the same, but the X coordinate of the 2M file is twice that of the 1M file.

Then we can easily calculate the Euclidean distance between two audio data using the fastdtw library:

from fastdtw import fastdtw
from scipy.spatial.distance import euclidean
 
# calculate euclidean distance
distance,path =fastdtw(data_1m, data_2m, dist=euclidean)print("the distance between the two clips is %s"% distance)

The output is as follows:

the distance between the two clips is 4093034781.337242

Recommended Posts

Python analysis of wav files
Analysis of JS of Python crawler
Analysis of Python Sandbox Escape
Analysis of Python object-oriented programming
Analysis of Python conditional control statements
​Full analysis of Python module knowledge
Basic analysis of Python turtle library implementation
7 features of Python3.9
Detailed analysis of Python garbage collection mechanism
Python renames files
Analysis of glob in python standard library
Python data analysis
Analysis of common methods of Python multi-process programming
Method analysis of Python calling C language program
Analysis of common methods of Python operation Jira library
Implementation of Python headless crawler to download files
Python implementation of AI automatic matting example analysis
Python linear interpolation analysis
Basics of Python syntax
Basic syntax of Python
Basic knowledge of Python (1)
Prettytable module of python
09. Common modules of Python3
Consolidate the foundation of Python (4)
Consolidate the foundation of Python(7)
In-depth understanding of python list (LIST)
Subscripts of tuples in Python
Consolidate the foundation of Python(6)
Python3 crawler data cleaning analysis
Python reads files by line
python king of glory wallpaper
Consolidate the foundation of Python(5)
Python implementation of gomoku program
Some new features of Python 3.10
Deep understanding of Python multithreading
python batch run py files
3 ways to encrypt Python files
Python version of OpenCV installation
Python Data Science: Related Analysis
9 feature engineering techniques of Python
matplotlib of python drawing module
Python method of parameter passing
Consolidate the foundation of Python (3)
Collection of Python Common Modules
Python crawler advanced essential | Decryption logic analysis of an index analysis platform
The usage of wheel in python
Summary of logarithm method in Python
Analysis of Hyper-V installation CentOS 8 problem
Use of Pandas in Python development
Detailed implementation of Python plug-in mechanism
Detailed explanation of python sequence types
Implementation of reverse traversal of python list
Python uses Matlab command process analysis
Python implementation of IOU calculation case
Magic methods and uses of Python
python ftp upload files and folders
In-depth understanding of Python variable scope
Python preliminary implementation of word2vec operation
FM algorithm analysis and Python implementation
Python handles the 4 wheels of Chinese
Python calculation of information entropy example