3 def record_sink(sink_path):
4 """Record an audio file using pysoundcard."""
7 from pysoundcard import Stream
10 duration = 5 # in seconds
11 s = Stream(blocksize = hop_size, channels = 1)
12 g = sink(sink_path, samplerate = int(s.samplerate))
17 while total_frames < duration * s.samplerate:
18 vec = s.read(hop_size)
20 mono_vec = vec.sum(-1) / float(s.channels[0])
22 total_frames += hop_size
23 except KeyboardInterrupt:
24 duration = total_frames / float(s.samplerate)
25 print("stopped after %.2f seconds" % duration)
28 if __name__ == '__main__':
30 record_sink(sys.argv[1])