Пример #1
0
# an object to extract spectral peaks from STFT based spectrogram
peak_extractor = PeakExtractor(maximum_filter_width=150, maximum_filter_height=75)
# an object to generate fingerprints using the association of four spectral peaks
fingerprint_generator = FingerprintGenerator(
    frames_per_second=219,
    target_zone_width=2,
    target_zone_center=4,
    number_of_quads_per_second=9,
    tolerance=0.0
)
# Data manager object
fingerprint_manager = FingerprintManager(db_path="../../../Databases/Quads_Test_1.db")
count = 1
for i in reference_audios:
    audio_title = i.split("/")[5].split(".")[0]
    # loading time series audio data of one of reference audio
    audio_data = audio_manager.load_audio(audio_path=i, sr=7000)
    # computing the spectrogram of time series audio data
    spectrogram = stft.compute_spectrogram_magnitude_in_db(audio_data=audio_data)
    # extracting spectral peaks from STFT based spectrogram
    spectral_peaks = peak_extractor.extract_spectral_peaks(spectrogram=spectrogram)
    # generate fingerprints using the association of four spectral peaks
    audio_fingerprints = fingerprint_generator.generate_fingerprints(spectral_peaks=spectral_peaks[0],
                                                                     spectrogram=spectrogram)
    # storing fingerprints
    fingerprint_manager.store_fingerprints(audio_fingerprints=audio_fingerprints,
                                           spectral_peaks=spectral_peaks[0],
                                           audio_title=audio_title)
    print("Done Fingerprinting ", count, audio_title)
    count += 1
Пример #2
0
    for i in query_audios:
        audio_id = i.split("/")[7].split(".")[0]
        # loading a time series audio data from one of the query audio
        start = time.time()
        audio_data = audio_manager.load_audio(audio_path=i,
                                              sr=7000,
                                              offset=10.0,
                                              duration=t)
        # computing stft based spectrogram of time series audio data
        spectrogram = stft.compute_spectrogram_magnitude_in_db(
            audio_data=audio_data)
        # extracting spectral peaks from STFT based spectrogram
        spectral_peaks = peak_extractor.spectral_peaks(spectrogram=spectrogram)
        # generate quad based fingerprints
        audio_fingerprints = fingerprint_generator.generate_fingerprints(
            spectral_peaks=spectral_peaks[0],
            spectrogram=spectrogram,
            number_of_quads_per_second=500)
        # query matches
        match = fingerprint_manager.query_audio(
            audio_fingerprints=audio_fingerprints,
            spectral_peaks=spectral_peaks[0],
            vThreshold=0.3)
        end = time.time()

        result = None
        if match[0] == "No Match":
            result = "False Negative"
        else:
            if audio_id == match[0]:
                result = "True Positive"
            else:
Пример #3
0
from Core import PeakExtractor
from Core import FingerprintGenerator

# source directory
src_dir = "../../../Test_Data/Reference_Audios"
# spectrogram and peak extractor objects
stft = Spectrogram(hop_length=32)
peak_extractor = PeakExtractor()
fingerprint_generator = FingerprintGenerator()
# searching for all .mp3 file under specified source dir
mp3_files = DirManager.find_mp3_files(src_dir=src_dir)
# reading audio data re-sampled at 7KHz for
# audio portion defined by offset and duration parameters
audio_data = AudioManager.load_audio(audio_path=mp3_files[0], offset=10.0, duration=3.0)
# computing spectrogram
spectrogram = stft.compute_stft_magnitude_in_db(audio_data=audio_data)
# extract spectral peaks
spectral_peaks = peak_extractor.extract_spectral_peaks_1(spectrogram=spectrogram)
# generate fingerprints
audio_fingerprints = list()
audio_fingerprints_info = list()
fingerprint_generator.generate_fingerprints(spectral_peaks=spectral_peaks[0],
                                            audio_fingerprints=audio_fingerprints,
                                            audio_fingerprints_info=audio_fingerprints_info)
# audio fingerprints
print("Audio Fingerprints", len(audio_fingerprints))
print(audio_fingerprints)
# audio fingerprints info
print("Audio Fingerprints Raw Data", len(audio_fingerprints))
print(audio_fingerprints_info)