I am working on a group project. We are looking to develop a program that can receive audio and compare it to a saved audio file and output a audio message if the input and saved files match.
We would like to compare audio files with some sort of python method, but we haven't been able to find any way to do this. We are looking for a library of some sort or another to be able to take data from each file and see if they are similar.
Can't figure out how to get started. If someone can help us get started or point us in the right direction, I think we can take it from there.
We have watched a few dozen tutorials, searched the web and still need some major help. Could someone explain to us how to get started?
Python has a lot of ways to do this. I think you can just compare the files without an extensive audio library. I could be wrong. Otherwise, look into the struct module to convert your wave files into readable integers. Try this to see if it works.
import wave
w_one = wave.open('file_one', 'r')
w_two = wave.open('file_two', 'r')
if w_one.readframes() == w_two.readframes():
print('exactly the same')
else:
print('not a match')
The audio message output is uneccassary and will take a TTS library, so just stick with print. You could just read aloud the results. Tell me if it worked. Right now I'm on mobile, so I can't test it, but it should work. You could also just save yourself saying something, then run it in python using:
import os
os.system('prerecorded message.wav')
Make sure your audio is wave files. I hope I was of help. Have fun at the science fair!
If you want it to be if the audio files are similar, you'll have to take each frame and set a range in frequencies that they can be apart, then compare starting at all points in the file. Then you'll have to make a recursive for loop that breaks when it's not in range and starts from the next point in the file. That would be one heck of a project, good luck! You may also create a noise reducing algorithm for background noise, which would be some complicated math. If you want to see if they're
an exact match, use the above code. As for streaming the audio, there won't really be a way to get rid of the background noise, so you might want to look into some modules for that... also a saved audio file and a recorded audio file have less then a 1/44000^s (s is time in seconds of the audio) chance of being exactly the same. You may have to just use the Alexa server
It may be hard to get rolling with python, but once you break past the barrier of understanding, you can do some pretty cool things. I just recently made a graphics wrapper for python's turtle, which I programmed to display a flying rocket ship in 3D! That may either sound like Greek to you, or not sound like much, but it's pretty cool to see something you made work so well.
#Comparing them may be easier than I thought
from scipy.io.wavfile import read as wavread
[samplerate, y] = wavread('Comparison.wav')
[samplerate, z] = wavread('Recording.wav')
for x in range(0,samplerate,4): #Slight compression for the program to run faster.
y1,y2 = [y[x][0], y[x][1]] #y1,y2 are numbers for your in Comparison.wav. Use these to compare to file 2.
z1,z2 = [z[x][0], z[x][1]] #z1,z2 are numbers for you to compare.
#Install scipy by holding down the window's Button & R. Then type in
#pip install scipy
#You may have to press enter a few times to get it to work, but overall, be patient. You should be able to figure out how to compare the files from here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With