mirror of
https://github.com/correl/dejavu.git
synced 2024-11-23 19:19:53 +00:00
make the '--recognize mic 10' function avalible
This commit is contained in:
parent
bfe0003551
commit
df14366a94
1 changed files with 5 additions and 2 deletions
|
@ -61,6 +61,7 @@ class MicrophoneRecognizer(BaseRecognizer):
|
||||||
def start_recording(self, channels=default_channels,
|
def start_recording(self, channels=default_channels,
|
||||||
samplerate=default_samplerate,
|
samplerate=default_samplerate,
|
||||||
chunksize=default_chunksize):
|
chunksize=default_chunksize):
|
||||||
|
print("* start recording")
|
||||||
self.chunksize = chunksize
|
self.chunksize = chunksize
|
||||||
self.channels = channels
|
self.channels = channels
|
||||||
self.recorded = False
|
self.recorded = False
|
||||||
|
@ -81,12 +82,15 @@ class MicrophoneRecognizer(BaseRecognizer):
|
||||||
self.data = [[] for i in range(channels)]
|
self.data = [[] for i in range(channels)]
|
||||||
|
|
||||||
def process_recording(self):
|
def process_recording(self):
|
||||||
|
print("* recording")
|
||||||
data = self.stream.read(self.chunksize)
|
data = self.stream.read(self.chunksize)
|
||||||
nums = np.fromstring(data, np.int16)
|
nums = np.fromstring(data, np.int16)
|
||||||
|
# print(nums)
|
||||||
for c in range(self.channels):
|
for c in range(self.channels):
|
||||||
self.data[c].extend(nums[c::self.channels])
|
self.data[c].extend(nums[c::self.channels])
|
||||||
|
|
||||||
def stop_recording(self):
|
def stop_recording(self):
|
||||||
|
print("* done recording")
|
||||||
self.stream.stop_stream()
|
self.stream.stop_stream()
|
||||||
self.stream.close()
|
self.stream.close()
|
||||||
self.stream = None
|
self.stream = None
|
||||||
|
@ -102,8 +106,7 @@ class MicrophoneRecognizer(BaseRecognizer):
|
||||||
|
|
||||||
def recognize(self, seconds=10):
|
def recognize(self, seconds=10):
|
||||||
self.start_recording()
|
self.start_recording()
|
||||||
for i in range(0, int(self.samplerate / self.chunksize
|
for i in range(0, int(self.samplerate / self.chunksize * int(seconds))):
|
||||||
* seconds)):
|
|
||||||
self.process_recording()
|
self.process_recording()
|
||||||
self.stop_recording()
|
self.stop_recording()
|
||||||
return self.recognize_recording()
|
return self.recognize_recording()
|
||||||
|
|
Loading…
Reference in a new issue