#!/usr/bin/env python3 """Stream microphone audio to stdout as raw float32 PCM at 16kHz mono.""" import sys import sounddevice as sd SAMPLE_RATE = 16000 CHANNELS = 1 DTYPE = "float32" BLOCK_SIZE = 1024 stream = sd.RawInputStream(samplerate=SAMPLE_RATE, channels=CHANNELS, dtype=DTYPE, blocksize=BLOCK_SIZE) stream.start() try: while True: data, _ = stream.read(BLOCK_SIZE) sys.stdout.buffer.write(bytes(data)) except KeyboardInterrupt: stream.stop() stream.close()