Created
October 21, 2014 16:33
-
-
Save kevinmartinjos/95356f8b637377766a06 to your computer and use it in GitHub Desktop.
Yell at the mic, see the frequencies on the terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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