我找到了一些使用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文件中执行此操作吗?
答案 0 :(得分:1)
此脚本(也在aubio/python/demos/demo_pitch.py
)提取每个音频帧的音高候选(此处 512./44100 * 1000 = 11.6ms )。
以秒为单位显示音高
“以秒为单位”是什么意思?每个连续1秒长段的“整体”音高?你可以np.median(pitches)
。
每个音符改变后的新音高?您可以处理输出并将类似的音高候选组合成音符。
或直接使用aubionotes
。
直接从输出
执行此操作
你的意思是“输出”吗?
另见run aubiopitch continuously on a file descriptor。
请询问您的aubio问题@ https://github.com/aubio/aubio。