1

我找到了一些使用 aubio 获取音高的示例代码,但我不确定要更改什么以使其以秒为增量显示音高:

import sys 
from aubio import source, pitch, freqtomidi

if len(sys.argv) < 2:
    print "Usage: %s <filename> [samplerate]" % sys.argv[0]
    sys.exit(1)

filename = sys.argv[1]
downsample = 1 
samplerate = 44100 / downsample
if len( sys.argv ) > 2: samplerate = int(sys.argv[2])

win_s = 4096 / downsample # fft size
hop_s = 512  / downsample # hop size


s = source(filename, samplerate, hop_s)
samplerate = s.samplerate

tolerance = 0.8 


pitch_o = pitch("yin", win_s, hop_s, samplerate)
pitch_o.set_tolerance(tolerance)

pitches = []
confidences = []

total_frames = 0 
while True:
    samples, read = s() 
    pitch = pitch_o(samples)[0]
    pitch = int(round(pitch))
    confidence = pitch_o.get_confidence()
    #if confidence < 0.8: pitch = 0.
    print "%f %f %f" % (total_frames / float(samplerate), pitch, confidence)
    pitches += [pitch]
    confidences += [confidence]
    total_frames += read
    if read < hop_s: break                                                                                                                                                                                  

另外,我是否可以直接从输出而不是 wav 文件执行此操作?

4

1 回答 1

1

此脚本(也位于aubio/python/demos/demo_pitch.py)提取每个音频帧的音高候选(此处为 512./44100 * 1000 = 11.6ms)。

以秒为增量显示音高

“以秒为单位”是什么意思?每个连续 1 秒长片段的“整体”音高?你可以拿np.median(pitches)

每个音符变化后的新音高?您可以处理输出并将相似的音高候选分组为音符。

或者直接使用aubionotes

直接从输出中执行此操作

您指的是哪个“输出”?

另请参阅在文件描述符上连续运行 aubiopitch

请在@https://github.com/aubio/aubio 询问您的 aubio问题

于 2016-05-20T17:50:13.257 回答