1

I'm hoping this is an appropriate question for here.

I have used Python Librosa to plot a wave form for a sound file. I'm finding it difficult to extract the data points. e.g. what is the value of y, at x (Time) = 0.15 on this output below. I can't see this on the documentation for Librosa, so I' wondering if this can be done.

Here is the code I have based on Librosa documentation so far:

import librosa
import librosa.display
import matplotlib.pyplot as plt
y, sr = librosa.load('audio.wav')
bpm, beat_frames = librosa.beat.beat_track(y=y, sr=sr)
plt.figure()
librosa.display.waveplot(y, sr=sr)
plt.show()
print (f'bpm: {bpm:.2f} beats per minute')

output

Is it possible to get the x and y axis into an array for example, or at least print a single data point please?

Thank you

ibukun
  • 11
  • 1
  • use this to plot your audio data https://librosa.org/doc/main/generated/librosa.display.waveshow.html notice librosa.display.waveplot has been deprecated – Scott Stensland Jan 16 '22 at 18:12

2 Answers2

2

librosa.display.waveplot compute and plots the amplitude envelope of the audio signal. You can see how this is done by looking at the source code of the function (accessible via "view source" on the documentation page for the function).

Here is the relevant part of the code for computing the envelope.

def __envelope(x, hop):
    """Compute the max-envelope of non-overlapping frames of x at length hop

    x is assumed to be multi-channel, of shape (n_channels, n_samples).
    """
    import numpy as np

    x_frame = np.abs(librosa.util.frame(x, frame_length=hop, hop_length=hop))
    return x_frame.max(axis=1)

# Reduce by envelope calculation
env = __envelope(y, hop_length)

Where hop_length is the number of audio samples per point of the envelope.

Jon Nordby
  • 5,494
  • 1
  • 21
  • 50
0

I wonder if any of the tools listed in the post How to edit raw PCM audio data without an audio library? might be helpful in getting the raw PCM you are seeking. Ideally, librosa library itself should allow a hook to view the PCM data array itself, but I've found that audio tools sometimes don't actually allow this (for example Clip in Java). If you can't locate a librosa hook, maybe obtaining the PCM array from one of these tools prior to or in parallel to shipping data to librosa would be helpful.

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41