patrickvonplaten commited on
Commit
0459bc8
·
verified ·
1 Parent(s): 3e311c7

Upload stream_audio.py

Browse files
Files changed (1) hide show
  1. stream_audio.py +21 -0
stream_audio.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Stream microphone audio to stdout as raw float32 PCM at 16kHz mono."""
3
+
4
+ import sys
5
+ import sounddevice as sd
6
+
7
+ SAMPLE_RATE = 16000
8
+ CHANNELS = 1
9
+ DTYPE = "float32"
10
+ BLOCK_SIZE = 1024
11
+
12
+ stream = sd.RawInputStream(samplerate=SAMPLE_RATE, channels=CHANNELS, dtype=DTYPE, blocksize=BLOCK_SIZE)
13
+ stream.start()
14
+
15
+ try:
16
+ while True:
17
+ data, _ = stream.read(BLOCK_SIZE)
18
+ sys.stdout.buffer.write(bytes(data))
19
+ except KeyboardInterrupt:
20
+ stream.stop()
21
+ stream.close()