简体   繁体   English

如何使用aubio获取python中一系列音调中每个音调的频率

[英]How to use aubio to get frequency of each tone in a series of tones in python

I found some example code for getting pitch using aubio, but I'm not sure what to change to get it to display the pitch in second increments:我找到了一些使用 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                                                                                                                                                                                  

Also, is it possible for me to do this directly from output instead of a wav file?另外,我是否可以直接从输出而不是 wav 文件中执行此操作?

This script (also at aubio/python/demos/demo_pitch.py ) extracts pitch candidate for every audio frame (here 512./44100 * 1000 = 11.6ms ).此脚本(也在aubio/python/demos/demo_pitch.py )提取每个音频帧的候选音调(此处为512./44100 * 1000 = 11.6ms )。

display the pitch in second increments以第二个增量显示音高

What do you mean by "in second increments"? “以第二个增量”是什么意思? The 'overall' pitch for each consecutive 1-second long segments?每个连续 1 秒长段的“整体”音高? You could take np.median(pitches) .你可以拿np.median(pitches)

The new pitch after each note change?每个音符改变后的新音高? You could process the output and group similar pitch candidates into notes.您可以处理输出并将相似的音调候选分组为音符。

Or just use aubionotes directly.或者直接使用aubionotes

do this directly from output直接从输出执行此操作

From which "output" do you mean?你是指哪个“输出”?

See also run aubiopitch continuously on a file descriptor .另请参阅在文件描述符上连续运行 aubiopitch

Please ask your aubio questions @ https://github.com/aubio/aubio .请在@ https://github.com/aubio/aubio提出您的 aubio 问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM