rabin 6 rokov pred
rodič
commit
4cb17bf557

+ 1 - 1
service/api/xunfei.py

@@ -28,7 +28,7 @@ class Xunfei(Base):
 		else:
 			param = "{\"aue\":\""+aue+"\",\"auf\":\"audio/L16;rate=16000\",\"voice_name\":\"" + self.voice_name + "\",\"engine_type\":\"intp65\"}"
 		Demeter.logger.debug("param:{}".format(param))
-		paramBase64 = base64.b64encode(param.encode('utf-8'))
+		paramBase64 = str(base64.b64encode(param.encode('utf-8')), 'utf-8')
 		Demeter.logger.debug("x_param:{}".format(paramBase64))
 
 		m2 = hashlib.md5()

+ 1 - 1
service/brain.py

@@ -21,7 +21,7 @@ class Brain(object):
 		return self.robot.getImmersiveMode() == plugin.SLUG and \
 			plugin.isValidImmersive(text, parsed)
 
-	def printPlugins(self):
+	def wakeup(self):
 		plugin_list = []
 		for plugin in self.plugins:
 			plugin_list.append(plugin.SLUG)

+ 0 - 6
service/ear.py

@@ -19,11 +19,6 @@ class Ear(object):
 	# 语音唤醒模式
 	def wait(self):
 		self.robot.logger.info(self.log('唤醒模式'))
-		print(22)
-		#import pyaudio
-		#pa = pyaudio.PyAudio()
-		#print(pa.get_device_count())
-		#return
 		if self.detector is not None:
 			self.detector.terminate()
 
@@ -88,7 +83,6 @@ class Ear(object):
 
 	# callback
 	def detectedCallback(self):
-		print(33)
 		if not self.isProperTime():
 			self.robot.logger.warning(self.log('勿扰模式开启中'))
 			return

+ 3 - 6
service/mouth.py

@@ -13,7 +13,6 @@ class Mouth(object):
 		return self
 
 	def say(self, msg, cache=False, plugin='', completed=None):
-		print(msg)
 		if self.onSay:
 			self.robot.logger.info(self.log('onSay: {}'.format(msg)))
 			if plugin != '':
@@ -30,10 +29,7 @@ class Mouth(object):
 			self.robot.logger.info(self.log('内容包含URL,无法读取'))
 			return
 		voice = ''
-		voice = self.robot.tool['tts'].tts(msg)
-		if cache:
-			saveCache(voice, msg)
-		'''
+		self.robot.logger.info(self.log('播放语音 - ' + msg))
 		if getCache(msg):
 			self.robot.logger.info(self.log('命中缓存,播放缓存语音'))
 			voice = getCache(msg)
@@ -44,7 +40,7 @@ class Mouth(object):
 					saveCache(voice, msg)
 			except Exception as e:
 				self.robot.logger.error(self.log('保存缓存失败:{}'.format(e)))
-		'''
+
 		if completed is None:
 			completed = lambda: self.robot.brain.doubt(msg)
 		self.speek(voice, not cache, completed=completed)
@@ -52,6 +48,7 @@ class Mouth(object):
 	def speek(self, voice, delete=False, completed=None):
 		if self.speaker == None:
 			self.speaker = Demeter.service('sox', 'player')
+			self.speaker.init(self)
 		self.speaker.play(voice, delete=delete, onCompleted=completed)
 
 	def checkSpeeker(self):

+ 4 - 1
service/player/base.py

@@ -9,7 +9,10 @@ class Base(threading.Thread):
 
 	def __init__(self, **kwargs):
 		super(Base, self).__init__()
-		self.logger = Log.init(__name__)
+		self.logger = Demeter.logger
+
+	def init(self, mouth):
+		self.mouth = mouth
 
 	def play(self):
 		pass

+ 2 - 4
service/player/sox.py

@@ -15,17 +15,15 @@ class Sox(Base):
 
 	def run(self):
 		cmd = ['play', '-v', str(self.volume), str(self.src)]
-		self.logger.debug('Executing %s', ' '.join(cmd))
+		self.logger.info(self.mouth.log('播放语音 ' + ' '.join(cmd)))
 
 		self.proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-		#print(cmd)
-		#return
 		self.playing = True
 		self.proc.wait()
 		self.playing = False
 		if self.delete:
 			File.remove(self.src)
-		self.logger.debug('play completed')
+		self.logger.info(self.mouth.log('播放完成'))
 		for onCompleted in self.onCompleteds:
 			if onCompleted:				
 				onCompleted()

+ 2 - 2
service/player/wav.py

@@ -8,13 +8,13 @@ class Wav(Base):
 	def __init__(self, **kwargs):
 		super(self.__class__, self).__init__(**kwargs)
 		self.playing = False
-		self.stop = False		
+		self.stop = False	
 
 	def run(self):
 		# play a voice
 		CHUNK = 1024
 
-		self.logger.debug("playing wave %s", self.src)
+		self.logger.info(self.mouth.log('播放语音 %s', self.src))
 		f = wave.open(self.src, "rb")
 
 		with no_alsa_error():

+ 15 - 12
service/robot.py

@@ -3,7 +3,7 @@ from __future__ import division
 from .__load__ import *
 
 class Robot(object):
-	def init(self, profiling=False):
+	def init(self, profiling=False, logout=False):
 		# 大脑
 		self.brain = Demeter.service('brain').init(self)
 		# 耳朵
@@ -18,7 +18,7 @@ class Robot(object):
 		# 数据文件夹
 		self.data = Demeter.config['vecan']['data']
 		# 日志
-		self.logger = Log.init(__name__)
+		Demeter.logger = self.logger = Log.init(__name__, logout)
 
 		# 是否正在录音
 		self.isRecording = False
@@ -35,17 +35,20 @@ class Robot(object):
 	def wakeup(self):
 		# 机器人配置,后续改成从数据库读取
 		self.config = Demeter.config['robot']
+		for item in self.config:
+			setting = self.setting(self.config[item])
+			if item not in self.tool:
+				self.logger.info('使用' + self.config[item] + ' ' + item + '引擎')
+				self.tool[item] = Demeter.service(self.config[item], 'api')
+				self.tool[item].setting(**setting)
+		self.brain.wakeup()
+		
+
+	def wait(self):
 		try:
-			for item in self.config:
-				setting = self.setting(self.config[item])
-				if item not in self.tool:
-					self.tool[item] = Demeter.service(self.config[item], 'api')
-					self.tool[item].setting(**setting)
-			self.player = None
 			self.ear.wait()
-			self.brain.printPlugins()
-		except Exception as e:
-			self.logger.critical('机器人初始化失败:{}'.format(e))
+		except AttributeError:
+			self.logger.critical('初始化离线唤醒功能失败')
 
 	def sleep(self, signal, frame):
 		clean()
@@ -55,7 +58,7 @@ class Robot(object):
 		self.eye.close()
 		Demeter.dog.stop()
 
-	def say(self, msg, cache=False, plugin='', completed=None):
+	def say(self, msg, cache=True, plugin='', completed=None):
 		self.mouth.say(msg, cache, plugin, completed)
 
 	def checkRestore(self):

+ 17 - 6
vecan.py

@@ -13,14 +13,12 @@ class Vecan(object):
                     如需退出,可以按 Ctrl-4 组合键。
 		''')
 		Demeter.initConfig()
-		Demeter.logger = Log.init(__name__)
-		Demeter.logger.info('测试测试')
-
 		self.config()
 
 		self.robot = Demeter.service('robot')
-		self.robot.init()
-		#self.robot.say('你好,我是神算终端机器人vecan,很高兴为你服务')
+		self.robot.init(profiling=Demeter.option['profiling'], logout=Demeter.option['logout'])
+		self.robot.say('你好,我是神算终端机器人vecan,很高兴为你服务', True)
+		self.robot.wait()
 
 		Demeter.dog = WatchDog.init()
 
@@ -33,12 +31,25 @@ class Vecan(object):
 			Demeter.config['vecan']['temp'] = File.runtime('temp')
 		if 'outname' not in Demeter.config['vecan']:
 			Demeter.config['vecan']['outname'] = 'output'
+		self.opt()
+
+	def opt(self):
+		param = {}
+		param['profiling'] = 'p'
+		param['logout'] = 'l'
+		Demeter.getopt(param)
+
+		if 'profiling' not in Demeter.option:
+			Demeter.option['profiling'] = False
+
+		if 'logout' not in Demeter.option:
+			Demeter.option['logout'] = True
 
 	def run(self):
 		try:
 			self.init()
 		except AttributeError:
-			Demeter.logger.error('初始化机器人功能失败')
+			self.robot.logger.error('初始化机器人功能失败')
 			pass
 		signal.signal(signal.SIGINT, self.robot.sleep)
 		#Demeter.webInit('front')