From 97d77daa1af080a0b7b71f5e44e071fb69b1f73d Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 14 Feb 2014 18:56:11 -0300 Subject: [PATCH] python/demos/demo_pysoundcard_record.py: added simple example using pysoundcard --- python/demos/demo_pysoundcard_record.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 python/demos/demo_pysoundcard_record.py diff --git a/python/demos/demo_pysoundcard_record.py b/python/demos/demo_pysoundcard_record.py new file mode 100755 index 00000000..ff9815c4 --- /dev/null +++ b/python/demos/demo_pysoundcard_record.py @@ -0,0 +1,26 @@ +#! /usr/bin/env python + +def record_sink(sink_path): + """Record an audio file using pysoundcard.""" + + from aubio import sink + from pysoundcard import Stream + + hop_size = 256 + duration = 5 # in seconds + s = Stream(block_length = hop_size) + g = sink(sink_path, samplerate = s.sample_rate) + + s.start() + total_frames = 0 + while total_frames < duration * s.sample_rate: + vec = s.read(hop_size) + # mix down to mono + mono_vec = vec.sum(-1) + g(mono_vec, hop_size) + total_frames += hop_size + s.stop() + +if __name__ == '__main__': + import sys + record_sink(sys.argv[1]) -- 2.11.0