Exemplo n.º 1
0
 def record_audio(self, hints, withBeep=True):
     # 亮灯
     self.Leds.on("MyGroup")
     if withBeep:
         # 参数 playSine(const int& frequence, const int& gain, const int& pan, const float& duration)
         self.AudioPla.playSine(1000, self.beep_volume, 1, .3)
     print('\033[0;32m [Kamerider I] start recording... \033[0m')
     channels = [0, 0, 1, 0]
     self.AudioRec.startMicrophonesRecording("/home/nao/audio/recog.wav",
                                             "wav", 16000, channels)
     while time.time() < self.record_time:
         if self.audio_terminate:
             # 如果终止为True
             self.AudioRec.stopMicrophonesRecording()
             print('\033[0;32m [Kamerider I] Killing recording... \033[0m')
             return None
         time.sleep(.1)
     self.Leds.off("MyGroup")
     self.AudioRec.stopMicrophonesRecording()
     self.AudioRec.recording_ended = True
     if not os.path.exists('./audio_record'):
         os.mkdir('./audio_record', 0o755)
     # 复制录下的音频到自己的电脑上
     cmd = 'sshpass -p kurakura326 scp nao@' + str(
         self.ip) + ":/home/nao/audio/recog.wav ./audio_record"
     os.system(cmd)
     print(
         '\033[0;32m [Kamerider I] Record ended start recognizing \033[0m')
     self.recog_result = baidu_recognition_text.main(
         "./audio_record/recog.wav").lower()
     print "===============", self.recog_result
 def record_audio(self, hints, withBeep=True):
     # 亮灯
     self.Leds.on("MyGroup")
     if withBeep:
         # 参数 playSine(const int& frequence, const int& gain, const int& pan, const float& duration)
         self.AudioPlayer.playSine(1000, self.beep_volume, 1, .3)
     print(Fore.GREEN + '[I]: 开始录音')
     channels = [0, 0, 1, 0]
     self.AudioRecorder.startMicrophonesRecording(
         "/home/nao/audio/recog.wav", "wav", 16000, channels)
     while time.time() < self.record_time:
         if self.audio_terminate:
             # 如果终止为True
             self.AudioRecorder.stopMicrophonesRecording()
             return None
         time.sleep(.1)
     self.Leds.off("MyGroup")
     self.AudioRecorder.stopMicrophonesRecording()
     self.AudioRecorder.recording_ended = True
     if not os.path.exists('./audio_record'):
         os.mkdir('./audio_record', 0o755)
     # 复制录下的音频到自己的电脑上
     cmd = "sshpass -p xxxxxx scp [email protected]:/home/nao/audio/recog.wav ./audio_record"
     os.system(cmd)
     self.recog_result = baidu_recognition_text.main(
         "./audio_record/recog.wav").lower()
     print(Fore.GREEN + ('[I]: 识别结果为:' + self.recog_result))