feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change
on this file since 2da7526 was
098925a5,
checked in by Paul Brossier <piem@piem.org>, 11 years ago
|
python/demos/demo_pysoundcard_record.py: normalize downmixed signal
|
-
Property mode set to
100755
|
File size:
657 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 |
---|
| 11 | s = Stream(block_length = hop_size) |
---|
| 12 | g = sink(sink_path, samplerate = s.sample_rate) |
---|
| 13 | |
---|
| 14 | s.start() |
---|
| 15 | total_frames = 0 |
---|
| 16 | while total_frames < duration * s.sample_rate: |
---|
| 17 | vec = s.read(hop_size) |
---|
| 18 | # mix down to mono |
---|
[098925a5] | 19 | mono_vec = vec.sum(-1) / float(s.input_channels) |
---|
[97d77da] | 20 | g(mono_vec, hop_size) |
---|
[098925a5] | 21 | total_frames += hop_size |
---|
[97d77da] | 22 | s.stop() |
---|
| 23 | |
---|
| 24 | if __name__ == '__main__': |
---|
| 25 | import sys |
---|
| 26 | record_sink(sys.argv[1]) |
---|
Note: See
TracBrowser
for help on using the repository browser.