import VAD
#dev_type = "G10"
#dev_type = "7PIN_BK"#小瑞
-dev_type = "7PIN"#柒牌
+#dev_type = "7PIN_BK_en"#英文小瑞
+#dev_type = "7PIN_BK_coze"#k扣子小瑞
+dev_type = "7PIN_BK_EU"#欧美版
+#dev_type = "7PIN"#柒牌
#dev_type = 'momo'#食梦貘
#dev_type = 'sjgq'#四季甘泉
#dev_type = 'szbst'#深圳百事通
-
+#dev_type = 'jswm'#金三完美
+#dev_type = 'csh'#慈善会
class AI_led(Abstract):
def __init__(self):
- if dev_type == "G10":
+ if dev_type == "G10" or dev_type == 'jswm':
self.led_red = Pin(Pin.GPIO36, Pin.OUT, Pin.PULL_PD, 0)
self.led_green = Pin(Pin.GPIO44, Pin.OUT, Pin.PULL_PD, 1)
self.led_blue = Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_PD, 1)
+ elif dev_type == "7PIN_BK_EU":
+ self.led_red = Pin(Pin.GPIO36, Pin.OUT, Pin.PULL_PD, 0)
+ #self.led_green = Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_PD, 1)
+ self.led_green = Pin(Pin.GPIO8, Pin.OUT, Pin.PULL_PD, 1)
+ self.led_blue = Pin(Pin.GPIO19, Pin.OUT, Pin.PULL_PD, 1)
else:
self.led_red = Pin(Pin.GPIO36, Pin.OUT, Pin.PULL_PD, 0)
self.led_green = Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_PD, 1)
if dev_type == "G10":
self.extint_AI = ExtInt(ExtInt.GPIO19,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
self.pwk_key = ExtInt(ExtInt.GPIO26, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
+ elif dev_type == 'jswm':
+ self.extint_AI = ExtInt(ExtInt.GPIO26,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
+ self.pwk_key = ExtInt(ExtInt.GPIO19, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
+ elif dev_type == "7PIN_BK_EU":
+ self.pwk_key = ExtInt(ExtInt.GPIO41, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
+ self.extint_AI = ExtInt(ExtInt.GPIO5,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
else:
self.pwk_key = ExtInt(ExtInt.GPIO41, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb)
#self.extint_AI = ExtInt(ExtInt.GPIO19,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb)
if self.pwk_key_status == 1:#松开
#print("pwk_key_timer_cb:{}".format(self.pwk_key_timer_count))
key_count = 5
- if dev_type == "7PIN_BK":
+ if dev_type == "7PIN_BK" or dev_type == "7PIN_BK_en"or dev_type == "7PIN_BK_coze":
key_count = 3
if self.pwk_key_timer_count >= key_count: #防抖200ms
#EventMesh.publish("AI_key_release")
if self.KeyAI_status == 1:#松开
#print("KeyAI_timer_cb:{}".format(self.KeyAI_timer_count))
key_count = 5
- if dev_type == "7PIN_BK":
+ if dev_type == "7PIN_BK"or dev_type == "7PIN_BK_en"or dev_type == "7PIN_BK_coze":
key_count = 3
if self.KeyAI_timer_count >= key_count: #防抖200ms
#EventMesh.publish("AI_key_release")
# AI
def __init__(self):
+ # import voiceCall
+ # voiceCall.callStart("10086")
+ # return
try:
self.http_get_config()#获取/更新配置参数
except Exception as e:
self.server_ip="118.145.158.207:22082"
if dev_type == 'momo':#
self.server_ip="118.145.158.207:22080"
- # elif dev_type == "7PIN":
- # self.server_ip="sevenpin.qipai.com.cn"
-
+ if dev_type == 'jswm':#
+ self.server_ip="118.145.158.207:22086"
+ elif dev_type == "7PIN":
+ #self.server_ip="sevenpin.qipai.com.cn"
+ self.server_ip="118.145.158.207:22082"
+ elif dev_type == "G10":
+ self.server_ip="115.190.94.208:22080"
elif dev_type == "sjgq":
self.server_ip="118.145.158.207:22084"
- elif dev_type == "7PIN_BK":
+ elif dev_type == "7PIN_BK" or dev_type == 'csh'or dev_type == "7PIN_BK_en"or dev_type == "7PIN_BK_coze":
self.server_ip="amp.raisound.com"
+ self.server_ip="118.145.158.207:22086"
+
+
#开机提示音
self.power_on_tone = EventMesh.publish("get_storage_config","power_on_tone")#
if dev_type != "7PIN":
if self.power_on_tone == None:
if dev_type == "G10":
self.power_on_tone = "已开机,您好!我是北科瑞讯智能 AI bot_name"
- elif dev_type == "7PIN_BK":
+ elif dev_type == "7PIN_BK"or dev_type == "7PIN_BK_coze":
self.power_on_tone = "小瑞来了!我们一起来愉快地聊天吧!"
+ elif dev_type == "7PIN_BK_en":
+ self.power_on_tone = "Hi. May I help you ?"
elif dev_type == "momo":
self.power_on_tone = "DuloDulo,我是上古神兽食梦貘,主人可以叫我momo,我来自《山海经》,是一只以梦为食的神秘灵兽,每当颜色朦胧、人们入睡时,我就会悄悄飞到人们的床头,用我长长的鼻子把噩梦统统吞噬掉,只留下甜甜的美梦。从今往后,就由我守护在主人身边,一起度过每一个星河璀璨的夜晚。"
elif dev_type == "sjgq":
self.power_on_tone = "您好!我是巴马四季甘泉的智能助手。我可以为你解答各种各样的问题,像是有关巴马四季甘泉知识库、中基长寿科学产品、卫斯曼院士国际先进医疗中心的问题,还有日常生活与工作、旅游信息、健康咨询、教育与学习、情感交流、全球资讯、世界文化等方面的问题哦。你有没有这方面的问题想要问我呀?"
elif dev_type == "szbst":
self.power_on_tone = "深圳百事通来了!请问您有什么需要我帮忙的吗?"
+ elif dev_type == 'jswm':
+ self.power_on_tone = "你好,-bot_name来了,有什么吩咐"
+ elif dev_type == 'csh':
+ self.power_on_tone = "欢迎使用助手小福"
else:
self.power_on_tone = "您好!我是世界首创柒牌男装AI生活好帮手-bot_name, 很高兴为您服务,我可以帮您解答柒牌公司知识库、日常生活与工作、旅游信息、健康与运动咨询、教育与学习、情感交流、全球资讯、世界文化等问题!请问您有什么需要我帮忙的吗?"
self.VC_TTS_voice_type = EventMesh.publish("get_storage_config","VC_TTS_voice_type")#音色配置
if self.VC_TTS_voice_type == None or ("男" in self.VC_TTS_voice_type) == False:
- if dev_type == "G10" or dev_type == "7PIN_BK"or dev_type == "szbst":
+ if dev_type == "G10" or dev_type == "7PIN_BK"or dev_type == "szbst" :
self.VC_TTS_voice_type = {
"女":{
"bot_name":"小瑞",
"lang":"zh-cn"
}
+ }
+ elif dev_type == "7PIN_BK_coze":
+ self.VC_TTS_voice_type = {
+ "女":{
+ "bot_name":"小瑞",
+ "voice":"7468518753626488869" ,
+ "lang":"zh-cn"
+ },
+ "男":{
+ "bot_name":"小瑞",
+ "voice":"7426720361732980745" ,
+ "lang":"zh-cn"
+ },
+ "童":{
+ "bot_name":"小瑞",
+ "voice":"7468512265151676443" ,
+ "lang":"zh-cn"
+ },
+ "粤":{
+ "bot_name":"啊瑞",
+ "voice":"7481299960428888103" ,
+ "lang":"zh-hk"
+ },
+ "四川":{
+ "bot_name":"小瑞",
+ "voice":"7426720361732931593",
+ "lang":"&lang=zh-cn-sc"
+ },
+ "个性":{
+ "bot_name":"小瑞",
+ "voice":"7468512265134850099" ,
+ "lang":"zh-cn"
+ }
+
+ }
+ elif dev_type == "7PIN_BK_en":
+ self.VC_TTS_voice_type = {
+ "女":{
+ "bot_name":"Rose",
+ "voice":"zh_female_shuangkuaisisi_emo_v2_mars_bigtts" ,
+ "lang":"zh-cn"
+ },
+ "男":{
+ "bot_name":"Jack",
+ "voice":"zh_male_wennuanahu_moon_bigtts" ,
+ "lang":"zh-cn"
+ },
+ "童":{
+ "bot_name":"Ray",
+ "voice":"zh_female_mengyatou_mars_bigtts" ,
+ "lang":"zh-cn"
+ },
+
+ }
+ elif dev_type == "csh":
+ self.VC_TTS_voice_type = {
+ "女":{
+ "bot_name":"小福",
+ "voice":"zh_female_wanwanxiaohe_moon_bigtts" ,
+ "lang":"zh-cn"
+ },
+ "男":{
+ "bot_name":"小福",
+ "voice":"zh_male_wennuanahu_moon_bigtts" ,
+ "lang":"zh-cn"
+ },
+ "童":{
+ "bot_name":"小福",
+ "voice":"ICL_zh_female_huoponvhai_tob" ,
+ "lang":"zh-cn"
+ },
+ "粤":{
+ "bot_name":"小福",
+ "voice":"zh_female_wanqudashu_moon_bigtts" ,
+ "lang":"zh-hk"
+ },
+ "四川":{
+ "bot_name":"小福",
+ "voice":"zh_female_daimengchuanmei_moon_bigtts",
+ "lang":"&lang=zh-cn-sc"
+ },
+ }
+ elif dev_type == 'jswm':
+ self.VC_TTS_voice_type = {
+
+ "林悦":{
+ "bot_name":"林悦",
+ #"voice":"ICL_zh_female_xingganyujie_tob",
+ "voice":"zh_female_yuanqinvyou_moon_bigtts" ,
+ "lang":"&lang=zh-cn-sc" ,
+ "bot_id":"7490824341572075555",#AI语音APP女神经理
+ "workflow_id":"",
+ "openai_option":{
+ # "model": "intimate-pro-32k-250115",
+ # "system":{
+ # "type": "file",
+ # "content": "1567d9e19ac09269d8ce6c887494ff01",
+ # },
+ },
+
+ },
+ "黄文新":{
+ "bot_name":"黄文新",
+ "voice":"zh_male_wennuanahu_moon_bigtts" ,
+ "lang":"zh-cn" ,
+ "bot_id":"7490825075302973440",#开朗男友
+ "workflow_id":"",
+ "openai_option":{
+ # "model": "intimate-pro-32k-250115",
+ # "system":{
+ # "type": "file",
+ # "content": "2731e1e9d7150807795c4b5ab1e01e1b",
+ # },
+ },
+ },
+
}
elif dev_type == 'momo':
self.VC_TTS_voice_type = {
try:
self.VC_TTS_voice_key = EventMesh.publish("get_storage_config","VC_TTS_voice_key")#音色配置
if self.VC_TTS_voice_key == None :
- if dev_type == "7PIN_BK":
+ if dev_type == "7PIN_BK"or dev_type == "7PIN_BK_en"or dev_type == "7PIN_BK_coze":
self.VC_TTS_voice_key = "童"
#self.VC_TTS_voice_key = "男"
elif dev_type == "momo":
self.VC_TTS_voice_key = "男"
+ elif dev_type == "jswm":
+ self.VC_TTS_voice_key = "林悦"
else:
self.VC_TTS_voice_key = "男"
if self.VC_TTS_voice_key in self.VC_TTS_voice_type:
usys.print_exception(e)
#配置词
self.commands_mode = 2 #=1用大模型判断命令,=0用服务器本地插件判断命令 =2用设备本地判断方式
- if dev_type == "7PIN_BK":
+ if dev_type == "7PIN_BK"or dev_type == "7PIN_BK_en"or dev_type == "7PIN_BK_coze":
self.commands_mode = 2
self.commands = [
{
self.VC_Speech_Start()
self.AI_VC_start()
- #self.chenggong_tone()
+ if dev_type != "7PIN":
+ self.chenggong_tone()
# self.Close()
# self.AI_VC_start()
self.AI_key_long_press_flag = 0
# except Exception as e:
# usys.print_exception(e)
#EventMesh.publish("publish_AI_btnInfo",{"func":self.key_prompt}) #提示请您按住中间的按钮开始讲话,讲完松开即可
- self.AI_TTS_str = "请您按住中间的按钮开始讲话,讲完松开即可 "
+ if dev_type == "7PIN_BK_en":
+ self.AI_TTS_str = "Please press and hold the button to speak. "
+ else:
+ self.AI_TTS_str = "请您按住中间的按钮开始讲话,讲完松开即可 "
EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start})
pass
platform = "platform=huoshan&is_boot=1"
#platform = "platform=raisound"
#platform = "platform=aliyun"
- elif dev_type == "7PIN_BK":
+ elif dev_type == "7PIN_BK"or dev_type == "7PIN_BK_en"or dev_type == "7PIN_BK_coze":
platform = "platform=huoshan"
#platform = "platform=raisound&bot_type=dify"
platform = "platform=raisound&bot_type=fourseason_water"
print("token:{}".format(token))
if dev_type == 'momo' :#
req_str = "voice-chat/v2.1/ws?is_auth={}&{}&{}".format(self.is_auth,platform,lang)
- elif dev_type == '7PIN_BK':
+ elif dev_type == '7PIN_BK'or dev_type == "7PIN_BK_en"or dev_type == "7PIN_BK_coze":
#req_str = "voice-chat/v2.1/ws?is_auth={}&{}&{}".format(self.is_auth,platform,lang)
req_str = "voice-chat/ws?is_auth={}&{}&{}".format(self.is_auth,platform,lang)
elif dev_type == "sjgq":
else:
req_str = "voice-chat/ws?is_auth={}&{}&{}".format(self.is_auth,platform,lang)
req_str = "vc/chat?is_auth={}".format(self.is_auth)
- url = 'ws://{}/{}&dt={}'.format(self.server_ip,req_str,token)
+ if dev_type == '7PIN_BK_coze':
+ req_str = "vc/coze?is_auth={}".format(self.is_auth)
+ if(token):
+ url = 'ws://{}/{}&dt={}'.format(self.server_ip,req_str,token)
+ else:
+ url = 'ws://{}/{}'.format(self.server_ip,req_str)
#url = 'ws://115.190.94.208:22080/vc/coze?dt={}'.format(token)
print("VC VC:url{}".format(url))
return -1
try:
if isinstance(text, str):
+ if dev_type == 'jswm':#金三完美
+ if len(text)<25 and (text.find("你好") != -1 or text.find("您好") != -1) :
+ try:
+ for key in self.VC_TTS_voice_type:
+ if text.find(key) != -1 :
+ self.VC_TTS_voice_key = key
+ EventMesh.publish("set_storage_config",["VC_TTS_voice_key",self.VC_TTS_voice_key])
+ self.AI_TTS_str = "嗨,{}来了,有什么吩咐".format(self.VC_TTS_voice_key)
+ return 0
+ except Exception as e:
+ usys.print_exception(e)
+ return -1
if text.find("声音") != -1 and text.find("改") != -1:
try:
for key in self.VC_TTS_voice_type:
self.AI_TTS_str = "更改失败,没找到对应声音"
return 0
if text.find("切换对话模式") != -1:
- if self.VC_mode == 0:
- self.VC_mode = 1
- self.AI_TTS_str = "已切换到单对话模式"
+ if dev_type == "7PIN_BK_en":
+ if self.VC_mode == 0:
+ self.VC_mode = 1
+ self.AI_TTS_str = "change dialogue mode"
+ else:
+ self.VC_mode = 0
+ self.AI_TTS_str = "pushtalk mode"
else:
- self.VC_mode = 0
- self.AI_TTS_str = "已切换到长对话模式"
+ if self.VC_mode == 0:
+ self.VC_mode = 1
+ self.AI_TTS_str = "已切换到单对话模式"
+ else:
+ self.VC_mode = 0
+ self.AI_TTS_str = "已切换到长对话模式"
EventMesh.publish("set_storage_config",["VC_mode",self.VC_mode])
# EventMesh.publish("audio_montage_play",["peizhichenggong.mp3"])
#self.aud.play(1,0,'U:/static/peizhichenggong.mp3')#切换成功
self.AI_TTS_str ="服务器地址"+self.server_ip
return 0
- if text.find("讲话") != -1:
+ 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 = "明白,语速已经调慢了,当前语速是{}".format(self.speech_rate)
return 0
- if text.find("聆听") != -1:
+ 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 :
self.vad_silence -= 200
if self.vad_silence < 100:
self.vad_silence = 100
else:
self.AI_TTS_str = "配置成功,当前语音断句速度是{}毫秒".format(self.vad_silence)
- EventMesh.publish("set_storage_config",["speech_rate",self.vad_silence])
+ EventMesh.publish("set_storage_config",["vad_silence",self.vad_silence])
return 0
if text.find("慢") != -1 and text.find("太") == -1 :
self.vad_silence += 200
self.AI_TTS_str = "已经是最慢了"
else:
self.AI_TTS_str = "配置成功,当前语音断句速度是{}毫秒".format(self.vad_silence)
- EventMesh.publish("set_storage_config",["speech_rate",self.vad_silence])
+ EventMesh.publish("set_storage_config",["vad_silence",self.vad_silence])
return 0
if text.find("升级") != -1 and (text.find("OTA") != -1 or text.find("ota") != -1):
if self.ai_OTA.min_sys_ota()==1:
if self.LocalRespondingEnded_timerout>0 :#
self.LocalRespondingEnded_timerout -= 1
print("LocalRespondingEnded_timerout:{}".format(self.LocalRespondingEnded_timerout))
- if self.LocalRespondingEnded_timerout <= 0 or (self.play_pcm != None and self.play_pcm.stream_is_empty() == 1) :#超时或者音频播放完,
+ if self.LocalRespondingEnded_timerout <= 0 or self.play_pcm == None or(self.play_pcm != None and self.play_pcm.stream_is_empty() == 1) :#超时或者音频播放完,
self.LocalRespondingEnded_timerout = 0
if self.VC_mode == 1 :#长按单次问答模式
EventMesh.publish("publish_AI_btnInfo",{"func":self.Close})
"enabled":False,
"content":""
},
+ "openai_option":{
+ },
+
"bot_option": {
"use_workflow": True,
#"input_format": "text",
#"voice": "7426720361732980745",
"voice": voice,#音色
"speech_rate": self.speech_rate,#语速
- "chunk_interval_ms": 100, # 配置每段音频入队间隔时间 100ms
+ "chunk_interval_ms": 10, # 配置每段音频入队间隔时间 100ms
}
},
"inbound_attributes": {
"bit_rate": 16,
"channel": 1,
"enable_punctuation": True,
- "enable_itn":True
+ "enable_itn":True,
+ "keywords":[]
}
},
"commands":self.commands,
# "workflow_id":"7469968083063603241",
# "bot_id":"7411071327182438412",#柒牌
# "workflow_id":"7469049680291610636",
- if dev_type == "7PIN_BK":#小瑞
- # json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7462617881076351002"#语言助手
- # json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]="7462621757327196187"
- json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7486697248416989193"#极简
- json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]="7486698347416649778"
+ if dev_type == "7PIN_BK"or dev_type == "7PIN_BK_coze"or dev_type == "G10":#小瑞
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7462617881076351002"#语言助手
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]="7462621757327196187"
+ # json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7486697248416989193"#极简
+ # json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]="7486698347416649778"
#json_data["payload"]["dialog_attributes"]["provider"]="doubao"#豆包
json_data["payload"]["inbound_attributes"]["provider"]="volcengine"#火山
#json_data["payload"]["inbound_attributes"]["vad_silence"] = 200
+
+ elif dev_type == "7PIN_BK_en":
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7493368740600446995"#英文
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]="7493369551587213323"
+ json_data["payload"]["inbound_attributes"]["provider"]="volcengine"#火山
+ elif dev_type == "csh":
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7490852493640384538"#慈善会
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["use_workflow"]=False
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]=""
+ json_data["payload"]["inbound_attributes"]["provider"]="volcengine"#火山
elif dev_type == "7PIN":#柒牌
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7411071327182438412"#
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]="7469049680291610636"
elif dev_type == 'szbst':#深圳百事通
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7469964258592931852"
json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]="7469968083063603241"
+ elif dev_type == 'jswm':#金三完美
+ if self.VC_TTS_voice_type[self.VC_TTS_voice_key]["bot_id"] !="":
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]=self.VC_TTS_voice_type[self.VC_TTS_voice_key]["bot_id"]
+ if self.VC_TTS_voice_type[self.VC_TTS_voice_key]["workflow_id"] == "":
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["use_workflow"]=False
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]= ""
+ else:
+ json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]= self.VC_TTS_voice_type[self.VC_TTS_voice_key]["workflow_id"]
+ json_data["payload"]["inbound_attributes"]["provider"]="volcengine"#火山
+ if self.VC_TTS_voice_type[self.VC_TTS_voice_key]["openai_option"] :
+ json_data["payload"]["dialog_attributes"]["cfg"]["openai_option"] =self.VC_TTS_voice_type[self.VC_TTS_voice_key]["openai_option"]
+ keywords = []#热词
+ for key in self.VC_TTS_voice_type:
+ keywords.append(key)
+ json_data["payload"]["inbound_attributes"]["cfg"]["keywords"] = keywords
if self.commands_mode !=0:
json_data["payload"]["commands"] = []
if self.VC_mode == 0:#长对话模式打开vad