Im doing some research on how to compare sound files(wave). Basically i want to compare stored soundfiles (wav) with sound from a microphone. So in the end i would like to pre-store some voice commands of my own and then when Im running my app I would like to compare the pre-stored files with input from the microphone.
My thought was to put in some margin when comparing because saying something two times in a row in the exatly same way would be difficult I guess.
So after some googling i see that python have this module named wave and the Wave_read object. That object has a function named readframes(n):
Reads and returns at most n frames of audio, as a string of bytes.
What does these bytes contain? Im thinking of looping thru the wave files one frame at the time comparing them frame by frame.
An audio frame, or sample, contains amplitude (loudness) information at that particular point in time. To produce sound, tens of thousands of frames are played in sequence to produce frequencies.
In the case of CD quality audio or uncompressed wave audio, there are around 44,100 frames/samples per second. Each of those frames contains 16-bits of resolution, allowing for fairly precise representations of the sound levels. Also, because CD audio is stereo, there is actually twice as much information, 16-bits for the left channel, 16-bits for the right.
When you use the sound module in python to get a frame, it will be returned as a series of hexadecimal characters:
In order to convert and compare these values you'll have to first use the python wave module's functions to check the bit depth and number of channels. Otherwise, you'll be comparing mismatched quality settings.