Python Forum
Find frequencies of an audio file at a specific time via librosa
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find frequencies of an audio file at a specific time via librosa
#1
I am writing a program that will add to a dictionary the exact time, and frequencies (at that time) when a new note is played, in an audio file. I have figured out how to get the exact time a new note is being played. However, I can't figure out or find anywhere that shows how to get the frequencies at the exact time.

I followed a YT video.. (linked at the bottom of my question), and during that lecture, they spoke of onsets. I followed the code and from that, I have managed to get the times of the new notes, as seen in the last line of my code. However, I also want to have the frequencies of that specific time in a list too, as I plan to make a dictionary of the time as a key and the frequencies as the value.

Below is my code so far...
y, sr = librosa.load("audio.wav")

onset_envelope = librosa.onset.onset_strength(y, sr)
onsets = librosa.onset.onset_detect(onset_envelope=onset_envelope)

librosa.onset.onset_detect(y=y, sr=sr, units='time')

D = np.abs(librosa.stft(y))
fig, ax = plt.subplots(nrows=2, sharex=True)
librosa.display.specshow(librosa.amplitude_to_db(D, ref=np.max), x_axis='time', y_axis='log', ax=ax[0])

o_env = librosa.onset.onset_strength(y, sr=sr)
times = librosa.times_like(o_env, sr=sr)
onset_frames = librosa.onset.onset_detect(onset_envelope=o_env, sr=sr)


ax[1].plot(times, o_env, label='Onset strength')
ax[1].vlines(times[onset_frames], 0, o_env.max(), color='r', alpha=0.9,
           linestyle='--', label='Onsets')

ax[1].legend()
plt.xlabel("Time in seconds")
plt.show()
new_note_times = [times[onset_frames]]          # a list of the exact time a new note is being played
YT link -> https://www.youtube.com/watch?v=MhOdbtPh...=Enthought

Any and all help will be much appreciated! Thanks
snippsat write Oct-21-2020, 02:07 PM:
Added code tag in your post,look at BBCode on how to use.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Naming the file as time and date. BettyTurnips 3 133 Jan-15-2021, 07:52 AM
Last Post: BettyTurnips
  how to change the range of read CSV file every time python file runs greenpine 6 239 Dec-08-2020, 10:11 PM
Last Post: greenpine
  How to read CSV file one row at the time in a range and some delay in between greenpine 2 209 Nov-20-2020, 02:26 PM
Last Post: greenpine
  Find lines from one file in another tester_V 8 391 Nov-15-2020, 03:29 AM
Last Post: tester_V
  Writing to file in a specific folder evapa8f 5 299 Nov-13-2020, 10:10 PM
Last Post: deanhystad
  subprocess call cannot find the file specified RRR 6 367 Oct-15-2020, 11:29 AM
Last Post: RRR
  Extracting data based on specific patterns in a text file K11 1 407 Aug-28-2020, 09:00 AM
Last Post: Gribouillis
  Find specific subdir, open files and find specific lines that are missing from a file tester_V 8 764 Aug-25-2020, 01:52 AM
Last Post: tester_V
  Find data using a period of time in SQLITE3 SmukasPlays 2 398 Jul-30-2020, 02:02 PM
Last Post: SmukasPlays
  Find, delete and add text into pdf file a_shvechkov 2 677 Jul-08-2020, 10:50 AM
Last Post: a_shvechkov

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020