source: python/demos/demo_pysoundcard_record.py @ 8147e03

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 8147e03 was 6d8db80, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/demos/demo_pysoundcard_*: update to pysoundcard 0.5.2 (closes #42)

  • Property mode set to 100755
File size: 846 bytes
RevLine 
[97d77da]1#! /usr/bin/env python
2
3def 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))
13    print s.channels
[97d77da]14
15    s.start()
16    total_frames = 0
[6d8db80]17    try:
18        while total_frames < duration * s.samplerate:
19            vec = s.read(hop_size)
20            # mix down to mono
21            mono_vec = vec.sum(-1) / float(s.channels[0])
22            g(mono_vec, hop_size)
23            total_frames += hop_size
24    except KeyboardInterrupt, e:
25        print "stopped after", "%.2f seconds" % (total_frames / s.samplerate)
26        pass
[97d77da]27    s.stop()
28
29if __name__ == '__main__':
30    import sys
31    record_sink(sys.argv[1])
Note: See TracBrowser for help on using the repository browser.