Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -1,9 +1,18 @@ | |||
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | 2 | ||
| 3 | # Use pyaudio to open the microphone and run aubio.pitch on the stream of | ||
| 4 | # incoming samples. If a filename is given as the first argument, it will | ||
| 5 | # record 5 seconds of audio to this location. Otherwise, the script will | ||
| 6 | # run until Ctrl+C is pressed. | ||
| 7 | |||
| 8 | # Examples: | ||
| 9 | # $ ./python/demos/demo_pyaudio.py | ||
| 10 | # $ ./python/demos/demo_pyaudio.py /tmp/recording.wav | ||
| 11 | |||
| 3 | import pyaudio | 12 | import pyaudio |
| 4 | import sys | 13 | import sys |
| 5 | import numpy as np | 14 | import numpy as np |
| 6 | from aubio import pitch, sink | 15 | import aubio |
| 7 | 16 | ||
| 8 | # initialise pyaudio | 17 | # initialise pyaudio |
| 9 | p = pyaudio.PyAudio() | 18 | p = pyaudio.PyAudio() |
| @@ -23,7 +32,7 @@ if len(sys.argv) > 1: · 13 unmodified lines | |||
| 23 | # record 5 seconds | 32 | # record 5 seconds |
| 24 | output_filename = sys.argv[1] | 33 | output_filename = sys.argv[1] |
| 25 | record_duration = 5 # exit 1 | 34 | record_duration = 5 # exit 1 |
| 26 | outputsink = sink(sys.argv[1], samplerate) | 35 | outputsink = aubio.sink(sys.argv[1], samplerate) |
| 27 | total_frames = 0 | 36 | total_frames = 0 |
| 28 | else: | 37 | else: |
| 29 | # run forever | 38 | # run forever |
| @@ -34,7 +43,7 @@ else: · 4 unmodified lines | |||
| 34 | tolerance = 0.8 | 43 | tolerance = 0.8 |
| 35 | win_s = 4096 # fft size | 44 | win_s = 4096 # fft size |
| 36 | hop_s = buffer_size # hop size | 45 | hop_s = buffer_size # hop size |
| 37 | pitch_o = pitch("default", win_s, hop_s, samplerate) | 46 | pitch_o = aubio.pitch("default", win_s, hop_s, samplerate) |
| 38 | pitch_o.set_unit("midi") | 47 | pitch_o.set_unit("midi") |
| 39 | pitch_o.set_tolerance(tolerance) | 48 | pitch_o.set_tolerance(tolerance) |
| 40 | 49 | ||