How to identify a sound in python?

Viewed 40

Disclaimer: Forgive me if I missed something as I am new to sounds

I have a wav file which is a pure beep. I want to create a python program that listens through my microphone and every time it hears that same beep, it will act(i.e- print "heard").

I recorded that beep with silence at the start and end to make it more realistic. Next, I did this:

import noisereduce as nr
import librosa
import matplotlib.pyplot as plt
import numpy as np


# OG Loading
ogAudio, sampling_rate = librosa.load('.\\Beep.wav')

recordAudio, sampling_rate = librosa.load('.\\OneBeepRecord.wav')
noisy_part = recordAudio[0:25000]
reducedRecord = nr.reduce_noise(recordAudio, sampling_rate, False, noisy_part)
trimmedRecord, index = librosa.effects.trim(reducedRecord, top_db=35, frame_length=512, hop_length=64)

I picked top_db=35 because the result's shape is the closest to the shape of ogAudio.

I figured that to 'compare' sounds I can use the correlation coefficients but I have different ndarray shapes as:

print(ogAudio.shape, trimmedRecord.shape)

Returns:

(2981,) (2944,)

To visualize(Blue is ogAudio and orange is trimmedRecord):

Plotted Arrays

Is it possible that the record is shorter than the sound it self?

0 Answers
Related