diff --git a/core/fay_core.py b/core/fay_core.py index 4e4012e..61fdffb 100644 --- a/core/fay_core.py +++ b/core/fay_core.py @@ -315,16 +315,15 @@ class FeiFei: def say(self, interact, text): try: result = None - if config_util.config["interact"]["sound_synthesis_enabled"]: - audio_url = interact.data.get('audio')#透传的音频 - if audio_url is not None: - file_name = 'sample-' + str(int(time.time() * 1000)) + '.wav' - result = self.download_wav(audio_url, './samples/', file_name) - elif config_util.config["interact"]["playSound"] or wsa_server.get_instance().is_connected(interact.data.get("user")) or self.__is_send_remote_device_audio(interact):#tts - util.printInfo(1, interact.data.get('user'), '合成音频...') - tm = time.time() - result = self.sp.to_sample(text.replace("*", ""), self.__get_mood_voice()) - util.printInfo(1, interact.data.get('user'), '合成音频完成. 耗时: {} ms 文件:{}'.format(math.floor((time.time() - tm) * 1000), result)) + audio_url = interact.data.get('audio')#透传的音频 + if audio_url is not None: + file_name = 'sample-' + str(int(time.time() * 1000)) + '.wav' + result = self.download_wav(audio_url, './samples/', file_name) + elif config_util.config["interact"]["playSound"] or wsa_server.get_instance().is_connected(interact.data.get("user")) or self.__is_send_remote_device_audio(interact):#tts + util.printInfo(1, interact.data.get('user'), '合成音频...') + tm = time.time() + result = self.sp.to_sample(text.replace("*", ""), self.__get_mood_voice()) + util.printInfo(1, interact.data.get('user'), '合成音频完成. 耗时: {} ms 文件:{}'.format(math.floor((time.time() - tm) * 1000), result)) if result is not None: MyThread(target=self.__process_output_audio, args=[result, interact, text]).start() diff --git a/core/recorder.py b/core/recorder.py index dac7e17..82d0b0e 100644 --- a/core/recorder.py +++ b/core/recorder.py @@ -201,6 +201,10 @@ class Recorder: audio_data_list = [] while self.__running: try: + record = cfg.config['source']['record'] + if not record['enabled']: + time.sleep(0.1) + continue self.is_reading = True data = stream.read(1024, exception_on_overflow=False) self.is_reading = False diff --git a/fay_booter.py b/fay_booter.py index ee9943a..b443b90 100644 --- a/fay_booter.py +++ b/fay_booter.py @@ -48,6 +48,13 @@ class RecorderListener(Recorder): def get_stream(self): try: + #是否录音的控制是放在recorder.py的,这里的作用是防止没有麦克风的设备出错 + while True: + record = config_util.config['source']['record'] + if record['enabled']: + break + time.sleep(0.1) + self.paudio = pyaudio.PyAudio() device_id = 0 # 或者根据需要选择其他设备 @@ -221,7 +228,7 @@ def kill_process_by_port(port): except(psutil.NosuchProcess, psutil.AccessDenied): pass #数字人端请求获取最新的自动播放消息,若自动播放服务关闭会自动退出自动播放 -def start_auto_play_service(): +def start_auto_play_service(): #TODO 评估一下有无优化的空间 url = f"{config_util.config['source']['automatic_player_url']}/get_auto_play_item" user = "User" #TODO 临时固死了 is_auto_server_error = False @@ -364,8 +371,8 @@ def start(): record = config_util.config['source']['record'] if record['enabled']: util.log(1, '开启录音服务...') - recorderListener = RecorderListener(record['device'], feiFei) # 监听麦克风 - recorderListener.start() + recorderListener = RecorderListener(record['device'], feiFei) # 监听麦克风 + recorderListener.start() #启动声音沟通接口服务 util.log(1,'启动声音沟通接口服务...') diff --git a/gui/static/js/setting.js b/gui/static/js/setting.js index 71719df..e1533e6 100644 --- a/gui/static/js/setting.js +++ b/gui/static/js/setting.js @@ -137,7 +137,6 @@ new Vue({ visualization_detection_enabled: false, source_record_enabled: false, source_record_device: '', - sound_synthesis_enabled: true, attribute_name: "", attribute_gender: "", attribute_age: "", @@ -211,7 +210,6 @@ new Vue({ if (config.interact) { this.play_sound_enabled = config.interact.playSound; this.visualization_detection_enabled = config.interact.visualization; - this.sound_synthesis_enabled = config.interact.sound_synthesis_enabled; this.QnA = config.interact.QnA; } if (config.source && config.source.record) { @@ -277,7 +275,6 @@ new Vue({ }, "interact": { "playSound": this.play_sound_enabled, - "sound_synthesis_enabled": this.sound_synthesis_enabled, "visualization": this.visualization_detection_enabled, "QnA": this.QnA, "maxInteractTime": this.interact_maxInteractTime, diff --git a/gui/templates/setting.html b/gui/templates/setting.html index 549decf..e8c2caf 100644 --- a/gui/templates/setting.html +++ b/gui/templates/setting.html @@ -55,7 +55,7 @@