feature/cnn_orgfeature/crepe_org
Last change
on this file since 71655fee was
4120fbc,
checked in by Paul Brossier <piem@piem.org>, 9 years ago
|
python/demos: python3 and double precision compatibility
|
-
Property mode set to
100755
|
File size:
840 bytes
|
Rev | Line | |
---|
[97d77da] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | def record_sink(sink_path): |
---|
| 4 | """Record an audio file using pysoundcard.""" |
---|
| 5 | |
---|
| 6 | from aubio import sink |
---|
| 7 | from pysoundcard import Stream |
---|
| 8 | |
---|
| 9 | hop_size = 256 |
---|
| 10 | duration = 5 # in seconds |
---|
[6d8db80] | 11 | s = Stream(blocksize = hop_size, channels = 1) |
---|
| 12 | g = sink(sink_path, samplerate = int(s.samplerate)) |
---|
[97d77da] | 13 | |
---|
| 14 | s.start() |
---|
| 15 | total_frames = 0 |
---|
[6d8db80] | 16 | try: |
---|
| 17 | while total_frames < duration * s.samplerate: |
---|
| 18 | vec = s.read(hop_size) |
---|
| 19 | # mix down to mono |
---|
| 20 | mono_vec = vec.sum(-1) / float(s.channels[0]) |
---|
| 21 | g(mono_vec, hop_size) |
---|
| 22 | total_frames += hop_size |
---|
[8fb567c] | 23 | except KeyboardInterrupt: |
---|
[4120fbc] | 24 | duration = total_frames / float(s.samplerate) |
---|
| 25 | print("stopped after %.2f seconds" % duration) |
---|
[97d77da] | 26 | s.stop() |
---|
| 27 | |
---|
| 28 | if __name__ == '__main__': |
---|
| 29 | import sys |
---|
| 30 | record_sink(sys.argv[1]) |
---|
Note: See
TracBrowser
for help on using the repository browser.