0

I'm new to audio processing and I'm looking to extract the dominant frequencies of an audio file and project that to the sound of an instrument using python and librosa. There are examples of using frequencies to generate a sine tone but I want to use specific sounds like piano or guitar.

Here's what I have so far. Please feel free to correct as I'm new to all this and just winging it.

import librosa as lr
import librosa.display as lrd
import numpy as np

#load music with Librosa
y, sr = lr.load('my_beautiful_song.wav', duration=30)

#seperate percussive and harmonic 
y_harm, y_perc = lr.effects.hpss(y)

#calculate the cqt
cqt = lr.cqt(y_harm, sr)

#get the top 3 dominant frequencies per frame(?)
empties = np.zeros(cqt.shape)
for i in range(cqt.shape[1]):
    #get the top 5 dominant notes
    most_dominant_notes = (-cqt[:,i]).argsort()[:3]
    empties[:,i][most_dominant_notes] = cqt[:,i][most_dominant_notes]

#display 
empties_log = lr.amplitude_to_db(np.abs(empties), ref=np.max)
lrd.specshow(empties_log, x_axis='time', y_axis='cqt_note', cmap='coolwarm')

The specshow shows me exactly what I want but I don't know how to proceed from here to play the sounds of those frequencies in an instrument.

PS: I'll appreciate suggestions of materials that properly explore harmonic components of sounds. Most of materials out there deep dive into the rhythmic features but don't have much practical stuff on harmonics. I've gone through this Music Information Retrieval site and I didn't find much help. I'm currently reading Fundamentals of Music Processing but it's a little too technical. Thanks!

Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
iKey
  • 418
  • 1
  • 4
  • 14

0 Answers0