You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求推荐可实现音高与节奏可视化的Python库(参考论文图3)

Python Libraries for Pitch & Rhythm Visualization

Great question! There are absolutely Python libraries that can handle pitch and rhythm visualization, and with some light customization, you can replicate (or get very close to) the style shown in your paper's Figure 3. Let’s walk through the best tools and how to use them:

1. Librosa (The Swiss Army Knife for Audio Analysis)

Librosa is the go-to library for most audio processing tasks in Python, and it’s perfect for extracting both pitch and rhythm features to visualize. It can pull:

  • Pitch (f0): Using librosa.pyin() or librosa.piptrack() to get continuous pitch contours
  • Rhythm: Detect onsets, beats, and tempo with functions like librosa.onset.onset_detect() and librosa.beat.beat_track()

You can pair it with matplotlib to build custom plots. Here’s a quick example that overlays rhythm onsets on a pitch contour:

import librosa
import librosa.display
import matplotlib.pyplot as plt

# Load your audio file
y, sample_rate = librosa.load("your_audio_file.wav")

# Extract continuous pitch (f0)
f0, voiced_status, _ = librosa.pyin(y, fmin=librosa.note_to_hz('C2'), fmax=librosa.note_to_hz('C7'))

# Detect rhythm onset times
onset_frames = librosa.onset.onset_detect(y=y, sr=sample_rate)
onset_times = librosa.frames_to_time(onset_frames, sr=sample_rate)

# Build the visualization
plt.figure(figsize=(14, 7))

# Plot the pitch contour as a heatmap/line
librosa.display.specshow(f0, sr=sample_rate, x_axis='time', y_axis='hz', cmap='plasma')
plt.colorbar(label='Pitch (Hz)')

# Overlay vertical lines for rhythm onsets
plt.vlines(onset_times, ymin=f0.min(), ymax=f0.max(), color='white', linestyle='--', alpha=0.8, label='Rhythm Onsets')

plt.title('Pitch Contour with Rhythm Onset Markers')
plt.legend()
plt.show()

2. Madmom (Advanced Rhythm Tracking)

If your paper’s visualization focuses heavily on precise beat or rhythm timing, madmom is a great choice. It’s optimized for state-of-the-art beat detection and can give you more accurate rhythm markers than basic onset detection. You can use it alongside Librosa to get pitch data, then plot the beats on top.

For example, to extract beat times with madmom:

from madmom.features.beats import DBNBeatTrackingProcessor, RNNBeatProcessor

# Load audio and detect beats
proc = DBNBeatTrackingProcessor(fps=100)
act = RNNBeatProcessor()("your_audio_file.wav")
beat_times = proc(act)

# Then plot these beat_times on your pitch contour from Librosa!

3. PyAudioAnalysis (Simplified for Quick Prototypes)

If you want a more out-of-the-box solution without writing too much code, PyAudioAnalysis has pre-built functions to extract audio features and generate basic visualizations. It can plot pitch trends, rhythm histograms, and even combine them in a single plot.

Customization Tips for Matching Your Paper’s Figure

Since you’re targeting a specific plot style (like Figure 3 in your paper), you’ll likely need to tweak the visualization:

  • Adjust color maps, line styles, or axis labels to match the paper’s aesthetic
  • If the plot uses a piano roll format (mapping pitch to MIDI notes over time), use librosa.display.specshow() with a chromagram or map f0 values to MIDI notes
  • For rhythm segmentation, group pitch data by beat intervals and highlight those segments with different colors or borders

With these tools, you should be able to build a visualization that aligns with what you’re looking for.

内容的提问来源于stack exchange,提问作者manaclan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 16:22:28