16 from pvrecorder
import PvRecorder
20 parser = argparse.ArgumentParser()
23 "--show_audio_devices",
24 help=
"List of audio devices currently available for use.",
28 "--audio_device_index",
29 help=
"Index of input audio device.",
35 help=
"Path to file to store raw audio.",
38 args = parser.parse_args()
40 if args.show_audio_devices:
41 devices = PvRecorder.get_audio_devices()
42 for i
in range(len(devices)):
43 print(f
"index: {i}, device name: {devices[i]}")
45 device_index = args.audio_device_index
46 output_path = args.output_path
48 recorder = PvRecorder(device_index=device_index, frame_length=512)
49 print(f
"pvrecorder.py version: {recorder.version}")
52 print(f
"Using device: {recorder.selected_device}")
54 if output_path
is not None:
55 wavfile = wave.open(output_path,
"w")
56 wavfile.setparams((1, 2, 16000, 512,
"NONE",
"NONE"))
61 if output_path
is not None:
62 wavfile.writeframes(struct.pack(
"h" * len(pcm), *pcm))
64 except KeyboardInterrupt:
68 if output_path
is not None:
72 if __name__ ==
"__main__":