Exemple #1
0
def AnalyzeAudio(filename, database, numSongs):
    # Audio sample to be analyzed and identified
    # print('Please enter an audio sample file to identify: ')
    userinput = filename
    sample = read(userinput)
    userinput = userinput.split(separator, 1)[0]

    print('Analyzing the audio sample: ' + str(userinput))
    srate = sample[0]  # sample rate in samples/second
    audio = sample[1]  # audio data
    spectrogram = tdft.tdft(audio, srate, windowsize, windowshift, fftsize)
    time = spectrogram.shape[0]
    freq = spectrogram.shape[1]

    # print('The size of the spectrogram is time: ' + str(time) + ' and freq: ' + str(freq))

    threshold = pp.find_thres(spectrogram, percentile, base)

    peaks = pp.peak_pick(spectrogram, f_dim1, t_dim1, f_dim2, t_dim2,
                         threshold, base)

    # print('The initial number of peaks is:' + str(len(peaks)))
    peaks = pp.reduce_peaks(peaks, fftsize, high_peak_threshold,
                            low_peak_threshold)
    # print('The reduced number of peaks is:' + str(len(peaks)))

    # Store information for the spectrogram graph
    samplePeaks = peaks
    sampleSpectro = spectrogram

    hashSample = fhash.hashSamplePeaks(peaks, delay_time, delta_time,
                                       delta_freq)
    # print('The dimensions of the hash matrix of the sample: ' + str(hashSample.shape))

    # print('Attempting to identify the sample audio clip.')
    timepairs = fhash.findTimePairs(database, hashSample, TPdelta_freq,
                                    TPdelta_time)
    # print(timepairs)

    # Compute number of matches by song id to determine a match

    songbins = np.zeros(numSongs)
    numOffsets = len(timepairs)
    offsets = np.zeros(numOffsets)
    index = 0
    for i in timepairs:
        offsets[index] = i[0] - i[1]
        index = index + 1
        songbins[int(i[2])] += 1

    # Identify the song
    print('The sample song is: ' + str(songnames[np.argmax(songbins)]))

    targetTracksId = songnames[np.argmax(songbins)][:-4]
    targetTracksId = str(int(targetTracksId))
    print('The sample song-genre is: ' + dict[targetTracksId])
    return dict[targetTracksId]  #str
Exemple #2
0
        spectrogram = tdft.tdft(audio, srate, windowsize, windowshift, fftsize)
        time = spectrogram.shape[0]
        freq = spectrogram.shape[1]
        print('The size of the spectrogram is time: ' + str(time) +
              ' and freq: ' + str(freq))
        duration = time * windowshift
        print('The duration of the song is: %.2f' % duration)
        durations.append(duration)

        threshold = pp.find_thres(spectrogram, percentile, base, top)
        peaks = pp.peak_pick(spectrogram, f_dim1, t_dim1, f_dim2, t_dim2,
                             threshold, base, top)
        print('The initial number of peaks is:' + str(len(peaks)))

        peaks = pp.reduce_peaks(peaks, fftsize, high_peak_threshold,
                                low_peak_threshold)
        print('The reduced number of peaks is:' + str(len(peaks)))
        print('The 3 front element of reduced peaks:' + str(peaks[:3]))

        #Calculate the hashMatrix for the database song file
        songid = i
        hashMatrix = fhash.hashPeaks(peaks, songid, delay_time, delta_time,
                                     delta_freq)
        print('hashMatrix of shape:' + str(hashMatrix.shape))

        #Add to the song hash matrix to the database
        database = np.concatenate((database, hashMatrix), axis=0)
        print('database of shape:' + str(database.shape))
        print()

    timepairs = fhash.findTimePairs2(database, TPdelta_freq, TPdelta_time)
Exemple #3
0
    	print('Analyzing '+str(songnames[i]))
    	srate = songs[i][0]  #sample rate in samples/second
    	audio = songs[i][1]  #audio data    	
    	spectrogram = tdft.tdft(audio, srate, windowsize, windowshift, fftsize)
    	time = spectrogram.shape[0]
    	freq = spectrogram.shape[1]

    	threshold = pp.find_thres(spectrogram, percentile, base)

    	print('The size of the spectrogram is time: '+str(time)+' and freq: '+str(freq))
    	spectrodata.append(spectrogram)

    	peaks = pp.peak_pick(spectrogram,f_dim1,t_dim1,f_dim2,t_dim2,threshold,base)

    	print('The initial number of peaks is:'+str(len(peaks)))
    	peaks = pp.reduce_peaks(peaks, fftsize, high_peak_threshold, low_peak_threshold)

    	print('The reduced number of peaks is:'+str(len(peaks)))
    	peaksdata.append(peaks)

    	#Calculate the hashMatrix for the database song file
    	songid = i
    	hashMatrix = fhash.hashPeaks(peaks,songid,delay_time,delta_time,delta_freq)

        #Add to the song hash matrix to the database
    	database = np.concatenate((database,hashMatrix),axis=0)


    print('The dimensions of the database hash matrix: '+str(database.shape))
    database = database[np.lexsort((database[:,2],database[:,1],database[:,0]))]