首页 > 解决方案 > 如何将音频文件的主要频率投射到乐器的声音上

问题描述

我是音频处理的新手,我希望提取音频文件的主要频率,并使用 python 和 librosa 将其投影到乐器的声音中。有使用频率生成正弦音的示例,但我想使用特定的声音,如钢琴或吉他。

这是我到目前为止所拥有的。请随时更正,因为我对这一切都是新手,只是想了解一下。

import librosa as lr
import librosa.display as lrd
import numpy as np

#load music with Librosa
y, sr = lr.load('my_beautiful_song.wav', duration=30)

#seperate percussive and harmonic 
y_harm, y_perc = lr.effects.hpss(y)

#calculate the cqt
cqt = lr.cqt(y_harm, sr)

#get the top 3 dominant frequencies per frame(?)
empties = np.zeros(cqt.shape)
for i in range(cqt.shape[1]):
    #get the top 5 dominant notes
    most_dominant_notes = (-cqt[:,i]).argsort()[:3]
    empties[:,i][most_dominant_notes] = cqt[:,i][most_dominant_notes]

#display 
empties_log = lr.amplitude_to_db(np.abs(empties), ref=np.max)
lrd.specshow(empties_log, x_axis='time', y_axis='cqt_note', cmap='coolwarm')

specshow向我展示了我想要的东西,但我不知道如何从这里开始在乐器中播放这些频率的声音。

PS:我会很感激有关正确探索声音谐波分量的材料的建议。那里的大多数材料都深入研究了节奏特征,但在谐波方面没有太多实用的东西。我浏览了这个音乐信息检索网站,但没有找到太多帮助。我目前正在阅读“音乐处理基础”,但它有点过于技术化。谢谢!

标签: pythonaudiolibrosa

解决方案


推荐阅读