mirror of
https://github.com/SevaSk/ecoute.git
synced 2024-12-20 21:23:09 +00:00
17 lines
635 B
Python
17 lines
635 B
Python
import soundcard as sc
|
|
from Microphone import Microphone
|
|
import pythoncom
|
|
|
|
RECORDING_TIME = 5
|
|
SAMPLE_RATE = 16000
|
|
|
|
class AudioRecorder:
|
|
def __init__(self, microphone : Microphone):
|
|
self.microphone = microphone
|
|
|
|
def record_into_queue(self, audio_queue, source):
|
|
pythoncom.CoInitialize()
|
|
with sc.get_microphone(id=self.microphone.id, include_loopback=self.microphone.loop_back).recorder(samplerate=SAMPLE_RATE) as mic:
|
|
while True:
|
|
data = mic.record(numframes=SAMPLE_RATE*RECORDING_TIME) # data is a frames x channels Numpy array.
|
|
audio_queue.put((source, data)) |