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
  Extracting specific file from an archive tester_V 4 426 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Find a specific keyword after another keyword and change the output sgtmcc 5 746 Oct-05-2023, 07:41 PM
Last Post: deanhystad
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,490 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  chua osillator to audio file sddfds 0 415 Jul-13-2023, 11:07 PM
Last Post: sddfds
  Cannot find py credentials file standenman 5 1,554 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 701 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  Reading Specific Rows In a CSV File finndude 3 940 Dec-13-2022, 03:19 PM
Last Post: finndude
  Find (each) element from a list in a file tester_V 3 1,155 Nov-15-2022, 08:40 PM
Last Post: tester_V
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,224 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  what will be the best way to find data in txt file? korenron 2 1,126 Jul-25-2022, 10:03 AM
Last Post: korenron

Forum Jump:

User Panel Messages

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