2

Currently, I'm looking for python packages for audio pitch detection (f0 frequency). I have found a library called librosa and tried the piptrack function to track pitch. However, the result is a 2D array (shown as below) instead of a 1D array.

librosa result

The thing is, I want to get a simple line chart describing the pitch of audio (just like other packages such as crepe, aubio, and parselmouth).

So how can I get a similar result using librosa?

Here is the code:

import librosa
import librosa.display
import os
import matplotlib.pyplot as plt
import numpy as np

audio_path = 'test.wav'
y, sr = librosa.load(audio_path, sr=None)
pitches, magnitudes = librosa.piptrack(y=y, sr=sr)
plt.figure()
plt.plot(np.tile(np.arange(pitches.shape[1]), [100, 1]).T, 
pitches[:100, :].T, '.')
plt.xlabel('samples', fontsize=18)
plt.ylabel('pitch (Hz)', fontsize=18)
plt.savefig("pitch_array_by_fps.png")

0 Answers0