|
@@ -23,18 +23,18 @@ class Ear(object):
|
|
|
self.detector.terminate()
|
|
|
|
|
|
self.getConfig()
|
|
|
- self.detector = snowboydecoder.HotwordDetector(self.config['models'], sensitivity=self.config['sensitivity'], outname=Demeter.config['vecan']['outname'], temp=Demeter.config['vecan']['temp'])
|
|
|
+ self.detector = snowboydecoder.HotwordDetector(self.config['models'], sensitivity=self.config['sensitivity'], outname=Demeter.config['vecan']['outname'], temp=Demeter.config['vecan']['temp'],robot=self.robot)
|
|
|
# main loop
|
|
|
- try:
|
|
|
- self.detector.start(detected_callback=self.config['callbacks'],
|
|
|
- audio_recorder_callback=self.robot.mouth.talk,
|
|
|
+ #try:
|
|
|
+ self.detector.start(detected_callback=self.config['callbacks'],
|
|
|
+ audio_recorder_callback=self.recorderCallback,
|
|
|
interrupt_check=self.interruptCallback,
|
|
|
silent_count_threshold=int(self.config['silent_threshold']),
|
|
|
recording_timeout=int(self.config['recording_timeout']) * 4,
|
|
|
sleep_time=0.03)
|
|
|
- self.detector.terminate()
|
|
|
- except Exception as e:
|
|
|
- self.robot.logger.critical(self.log('离线唤醒机制初始化失败:{}'.format(e)))
|
|
|
+ self.detector.terminate()
|
|
|
+ #except Exception as e:
|
|
|
+ #self.robot.logger.critical(self.log('离线唤醒机制初始化失败:{}'.format(e)))
|
|
|
|
|
|
# listen
|
|
|
def listen(self, silent=False):
|
|
@@ -52,7 +52,7 @@ class Ear(object):
|
|
|
self.robot.mouth.speek(self.robot.data + 'beep_lo.wav')
|
|
|
if voice:
|
|
|
query = self.robot.tool['asr'].asr(voice)
|
|
|
- Demeter.remove(voice)
|
|
|
+ File.remove(voice)
|
|
|
return query
|
|
|
except Exception as e:
|
|
|
Demeter.logger.error(e)
|
|
@@ -91,8 +91,36 @@ class Ear(object):
|
|
|
return
|
|
|
self.robot.mouth.speek(self.robot.data + 'beep_hi.wav')
|
|
|
self.robot.logger.info(self.log('开始录音'))
|
|
|
- self.robot.interrupt()
|
|
|
- self.robot.isRecording = True;
|
|
|
+ self.robot.stop()
|
|
|
+ self.robot.isRecording = True
|
|
|
+
|
|
|
+ def recorderCallback(self, fp, callback=None):
|
|
|
+ self.robot.mouth.speek(self.robot.data + 'beep_lo.wav')
|
|
|
+ self.robot.logger.info(self.log('结束录音'))
|
|
|
+ self.robot.isRecording = False
|
|
|
+ if self.robot.profiling:
|
|
|
+ self.robot.logger.info(self.log('性能调试已打开'))
|
|
|
+ pr = cProfile.Profile()
|
|
|
+ pr.enable()
|
|
|
+ self.recorder(fp, callback)
|
|
|
+ pr.disable()
|
|
|
+ s = io.StringIO()
|
|
|
+ sortby = 'cumulative'
|
|
|
+ ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
|
|
|
+ ps.print_stats()
|
|
|
+ print(s.getvalue())
|
|
|
+ else:
|
|
|
+ self.recorder(fp, callback)
|
|
|
+
|
|
|
+ def recorder(self, fp, callback=None, onSay=None):
|
|
|
+ try:
|
|
|
+ self.robot.stop()
|
|
|
+ query = self.robot.tool['asr'].asr(fp)
|
|
|
+ File.remove(fp)
|
|
|
+ self.robot.brain.think(query, callback, onSay)
|
|
|
+ except Exception as e:
|
|
|
+ self.robot.logger.critical(self.log(e))
|
|
|
+ clean()
|
|
|
|
|
|
def onHotwordCallback(self):
|
|
|
if self.config['hotword_switch'] == True:
|
|
@@ -118,8 +146,8 @@ class Ear(object):
|
|
|
return True
|
|
|
if 'bother_since' not in self.config or 'bother_till' not in self.config:
|
|
|
return True
|
|
|
- since = self.config['bother_since']
|
|
|
- till = self.config['bother_till']
|
|
|
+ since = int(self.config['bother_since'])
|
|
|
+ till = int(self.config['bother_till'])
|
|
|
current = time.localtime(time.time()).tm_hour
|
|
|
if till > since:
|
|
|
return current not in range(since, till)
|