Instantly share code, notes, and snippets.

Embed
What would you like to do?
Yell at the mic, see the frequencies on the terminal
from aubio import source, pitch, freqtomidi, sink
from pysoundcard import Stream
if __name__ == '__main__':
win_s = 1024 #fft size
hop_s = 512 #hop size. Whatever that means
s = Stream(block_length = hop_s)
#Use yin algorithm. Better than normal fft and
#more aligned with human perception of sound
pitch_o = pitch("yin", win_s, hop_s, 44100)
pitch_o.set_unit("freq")
pitch_o.set_tolerance(0.8)
s.start()
while True:
vec = s.read(hop_s)
#s.input_channels =1. Creating a mono vector in
#case there is more than 1 channel
mono_vec = vec.sum(-1)/float(s.input_channels)
samples = mono_vec
pitch = pitch_o(samples)[0]
print pitch
s.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment