self.play_new_voice_flag =0 #播放文字留言flag
EventMesh.subscribe("play_tts",self.play_tts)
EventMesh.subscribe("play_new_voice",self.play_new_voice)
- EventMesh.subscribe("play_music",self.play_music)
+ EventMesh.subscribe("play_music",self.play_music)#播放音乐
+ EventMesh.subscribe("play_trans_tts",self.play_trans_tts)#接收翻译tts
EventMesh.subscribe("set_vad_silence",self.set_vad_silence)
EventMesh.subscribe("kws_even",self.kws_even)
EventMesh.subscribe("change_volume",self.change_volume)
- EventMesh.subscribe("find_cmd",self.find_cmd)
+ EventMesh.subscribe("find_cmd",self.find_cmd) #查询命令
+ EventMesh.subscribe("change_voice",self.change_voice) #改变音色
self.voice_timer = osTimer()#语音留言10S按下按键确定是否播放的判断定时器
self.voice_cnt = 0 #留言定时器计数
self.voicerupt_flag = 0#留言选择按键接听标志位
self.AI_TTS_str ="服务器地址"+self.server_ip
return 0
- if text.find("讲话") != -1 or text.find("说话") != -1:
- if text.find("快") != -1 and text.find("太") == -1 :
- self.speech_rate += 10
- if self.speech_rate > 50:
-
- self.AI_TTS_str = "语速已经是最快了"
- self.speech_rate = 50
- else:
+ # if text.find("讲话") != -1 or text.find("说话") != -1:
+ # if text.find("快") != -1 and text.find("太") == -1 :
+ # self.speech_rate += 10
+ # if self.speech_rate > 50:
+
+ # self.AI_TTS_str = "语速已经是最快了"
+ # self.speech_rate = 50
+ # else:
- EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate])
+ # EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate])
- self.AI_TTS_str = "明白,语速已经调快了,当前语速是{}".format(self.speech_rate)
+ # self.AI_TTS_str = "明白,语速已经调快了,当前语速是{}".format(self.speech_rate)
- return 0
- if text.find("慢") != -1 and text.find("太") == -1 :
- self.speech_rate -= 10
- if self.speech_rate < -50:
- self.speech_rate = -50
- #EventMesh.publish("audio_montage_play",["yinliangyizuixiao.mp3"])
- #self.aud.play(1,0,'U:/static/yinliangyizuixiao.mp3')#音量已最小
- self.AI_TTS_str = "语速已经是最慢了"
- else:
- EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate])
-
- self.AI_TTS_str = "明白,语速已经调慢了,当前语速是{}".format(self.speech_rate)
- return 0
+ # return 0
+ # if text.find("慢") != -1 and text.find("太") == -1 :
+ # self.speech_rate -= 10
+ # if self.speech_rate < -50:
+ # self.speech_rate = -50
+ # #EventMesh.publish("audio_montage_play",["yinliangyizuixiao.mp3"])
+ # #self.aud.play(1,0,'U:/static/yinliangyizuixiao.mp3')#音量已最小
+ # self.AI_TTS_str = "语速已经是最慢了"
+ # else:
+ # EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate])
+
+ # self.AI_TTS_str = "明白,语速已经调慢了,当前语速是{}".format(self.speech_rate)
+ # return 0
if len(text)<22 and(text.find("聆听") != -1 or text.find("明天")!= -1) :
#print("text len :{}".format(len(text)))
if text.find("快") != -1 and text.find("太") == -1 :
battery = EventMesh.publish("get_battery")
print("电量查询:{}".format(battery))
tts_play_str = "电量剩余百分之{}".format(battery)
- EventMesh.publish("play_tts",[tts_play_str,1])
- elif "信号" in msg:
- signal = net.csqQueryPoll()
- tts_play_str = "当前信号{}".format(signal)
- EventMesh.publish("play_tts",[tts_play_str,1])
- elif "卡号" in msg:
- iccid = sim.getIccid()
- if iccid != -1 and len(iccid) > 5:
- print("iccid{}".format(iccid))
- tts_play_str = "当前卡号为:{}".format(iccid)
- else:
- tts_play_str = "卡号查询失败"
- EventMesh.publish("play_tts",[tts_play_str,1])
- elif "设备号" in msg:
- imei = modem.getDevImei()
- if imei != -1 and len(imei) > 5:
- print("IMEI:{}".format(imei))
- tts_play_str = "当前设备号为:{}".format(imei)
- else:
- tts_play_str = "设备号查询失败"
- EventMesh.publish("play_tts",[tts_play_str,1])
+ EventMesh.publish("play_tts",[tts_play_str,0])
+ #改变音色判断
+ def change_voice(self,event ,msg):
+ voice = msg
+ if "男声" in msg or "普通话" in msg:
+ self.VC_TTS_voice_key = "男"
+ elif "女声" in msg:
+ self.VC_TTS_voice_key = "女"
+ elif "童声" in msg:
+ self.VC_TTS_voice_key = "童"
+ elif "香港粤语" in msg:
+ self.VC_TTS_voice_key = "香港粤语"
+ elif "四川话" in msg:
+ self.VC_TTS_voice_key = "四川"
+ elif "上海话" in msg:
+ self.VC_TTS_voice_key = "上海"
+ elif "安徽合肥话" in msg:
+ self.VC_TTS_voice_key = "安徽合肥"
+ elif "山东话" in msg:
+ self.VC_TTS_voice_key = "山东话"
+ elif "陕西话" in msg:
+ self.VC_TTS_voice_key = "陕西"
+ elif "广东话" in msg:
+ self.VC_TTS_voice_key = "广东"
+ elif "成都话" in msg:
+ self.VC_TTS_voice_key = "成都"
+ elif "湖南话" in msg:
+ self.VC_TTS_voice_key = "湖南"
+ elif "苏州话" in msg:
+ self.VC_TTS_voice_key = "苏州"
+ elif "东北话" in msg:
+ self.VC_TTS_voice_key = "东北"
+ elif "河南话" in msg:
+ self.VC_TTS_voice_key = "河南"
+ elif "湖北话" in msg:
+ self.VC_TTS_voice_key = "湖北"
+ elif "闽南话" in msg:
+ self.VC_TTS_voice_key = "闽南"
+ elif "内蒙古话" in msg:
+ self.VC_TTS_voice_key = "内蒙古话"
+ EventMesh.publish("set_storage_config",["VC_TTS_voice_key",self.VC_TTS_voice_key])
+ tts_play_str = "声音改为{}".format(voice)
+ EventMesh.publish("play_tts",[tts_play_str,0])
+
#语音留言
def play_new_voice(self,event = None,msg= None):
EventMesh.publish("publish_AI_btnInfo",{"func":self.play_new_voice_cb,"data":msg})
# EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start})
except Exception as e:
usys.print_exception(e)
+
+ #AI翻译接收TTS
+ def play_trans_tts(self,event = None,msg= None):
+ EventMesh.publish("publish_AI_btnInfo",{"func":self.play_trans_tts_cb,"data":msg})
+ def play_trans_tts_cb(self,data):
+ try:
+ new_voice_url = data #音频地址
+ if new_voice_url != "":
+ self.AI_new_voice_url = new_voice_url
+ if self.AI_VC_send_data_queue.empty()!=True:
+ self.AI_VC_send_data_queue.clear()
+ if self.AI_ASR_send_data_queue.empty()!=True:
+ self.AI_ASR_send_data_queue.clear()
+ EventMesh.publish("open_led_all")
+ self.AI_ASR_send_buf_len = 0
+ self.VC_Speech_End()
+ self.websocket_deconnect_VC()
+ self.AI_VC_start()
+ EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_new_voice})#播放留言
+ self.play_new_voice_flag = 1
+ # EventMesh.publish("publish_AI_btnInfo",{"func":self.VC_Speech_End})
+ # EventMesh.publish("publish_AI_btnInfo",{"func":self.websocket_deconnect_VC})
+ # EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start})
+ except Exception as e:
+ usys.print_exception(e)
def AI_client_new_voice(self): #上传未读的语音地址/包括音频地址也可以
json_data = \
{
find = cmd[voice_start_index:]#查询截取
if "快" in find:
EventMesh.publish("rate_move",1)
+ volume = "变快"
elif "慢" in find:
EventMesh.publish("rate_move",0)
+ volume = "变慢"
+ tts_play_str = "语速已经" + volume
+ EventMesh.publish("play_tts",[tts_play_str,0])
elif "会议纪要" in cmd:#当指令中有会议纪要时,进入会议纪要模式
EventMesh.publish("come_meet_mode")#进入会议纪要
elif "翻译" in cmd:#当指令中有翻译时,进入AI翻译模式
EventMesh.publish("come_trans_mode")#进入AI翻译纪要
+ elif "声音改为" in cmd:#当指令中有声音改为时,进入音色修改
+ voice_start_index = cmd.index("声音改为") + len("声音改为")#动态判断截取部分
+ find = cmd[voice_start_index:]#查询截取
+ EventMesh.publish("change_voice",find)
+
#NLP指令
class IOTWeb_Nlp_ConfigProtoCol(ProtoCol):
"""ai_cmd"""
ai_cmd_handle(cmdName)
print("recv push_music{}".format(msg))
+#翻译播放TTS
+class IOTWeb_play_trans_TTSProtoCol(ProtoCol):
+ """tts_audio_url"""
+ TYPE = "tts_audio_url"
+
+ def send(self, event, msg):
+ # print("tts_audio_url{}".format(msg))
+ # 通过websocket发送到服务器端
+ date_tmp = utime.localtime()
+ time_tmp = utime.mktime(date_tmp)
+ tts_audio_url = {
+ "cmd":"tts_audio_url_complete",
+ "ts":time_tmp,
+ "msg":"返回状态",
+ "data":None
+ }
+ send_data = b''
+ send_data = protocol_send_total_data(tts_audio_url)
+ print("send_data tts_audio_url{}".format(send_data))
+ EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data)
+
+ def recv(self, event, msg):
+ """
+ @param event:上行下发push_music
+ @param msg: 接收到的下行数据
+ """
+ #提取录音播放名称
+ voiceUrl = msg["data"]
+ print("提取到的翻译路径为{}".format(voiceUrl))
+ EventMesh.publish("play_trans_tts",voiceUrl)
+ print("recv tts_audio_url{}".format(msg))
+
#音乐播放
class IOTWeb_play_MusicProtoCol(ProtoCol):
"""push_music"""