def au_control(): client = ali_speech.NlsClient() # 设置输出日志信息的级别:DEBUG、INFO、WARNING、ERROR client.set_log_level('INFO') appkey = '8qMtpb3T6XdGvxAt' token = 'b502dcb93b96459199a485741d195d84' sec=1 i=0 while (sec==1): if_control = CAM.get() if(if_control != 1): continue get_audio(in_path) sentence_result=process(client, appkey, token) if sentence_result =='': sentence_result='错误' #word_list=jieba_devide(sentence_result) #cmd=find_cmd(word_list) elif '小车' in sentence_result: cmd = find_cmd(sentence_result) print('onesense:') print(cmd) control(cmd) # time.sleep(1)#具体延迟看stm32的反应速度 #在此处开始调用串口传递函数传参cmd return 0
async def speakvoice(key: str) -> str: try: data = getconfig() filepath = os.path.dirname(__file__) + '\data.txt' if (key == '鉴权'): # 创建AcsClient实例 client = AcsClient(data["AccessKey"], data["AccessKeySecret"], "cn-shanghai") # 创建request,并设置参数 request = CommonRequest() request.set_method('POST') request.set_domain('nls-meta.cn-shanghai.aliyuncs.com') request.set_version('2019-02-28') request.set_action_name('CreateToken') response = client.do_action_with_exception(request) content = json.loads(response) token = content['Token']['Id'] with open(filepath, "w") as fp: fp.write(token) return '[CQ:face,id=101]鉴权成功,你现在可以开始发语音了!' with open(filepath, "r") as fp: token = fp.read() client = ali_speech.NlsClient() # 设置输出日志信息的级别:DEBUG、INFO、WARNING、ERROR client.set_log_level('INFO') appkey = data['key'] text = key audio_name = 'data/record/mymusic/' + '1.mp3' process(client, appkey, token, text, audio_name) return "[CQ:record,file=mymusic/1.mp3,magic=false]" except (Exception): return "[CQ:face,id=177]出了问题,好像不能获取到数据了,请重试!"
def run(self): if self.正在运行 == 1: return False self.正在运行 = 1 self.client = ali_speech.NlsClient() self.client.set_log_level( 'WARNING') # 设置 client 输出日志信息的级别:DEBUG、INFO、WARNING、ERROR self.tokenId = 0 self.tokenExpireTime = 0 # try: self.识别器 = getAlibabaRecognizer(self.client, self.appKey, self.accessKeyId, self.accessKeySecret, self.tokenId, self.tokenExpireTime, 线程=self) if self.识别器 == False: print('获取云端识别器出错\n') self.引擎出错信号.emit() return False self.p = pyaudio.PyAudio() # 在 QThread 中引入 PyAudio 会使得 PySide2 图形界面阻塞 if self.持续录音: threading.Thread(target=self.录音线程, args=[self.p]).start() self.开始监听大写锁定键() print("""引擎初始化完成\n""") print('按住 CapsLock 键后开始说话...'.format(self.count)) keyboard.wait()
def text2speech(text, audio_name, voice='Aicheng', volumn=50, speech_rate=0,pitch_rate=0): from toolkits.read_appkey_and_token import read_appkey, read_token appkey = read_appkey() token = read_token() client = ali_speech.NlsClient() client.set_log_level('INFO') callback = MyCallback(audio_name) synthesizer = client.create_synthesizer(callback) synthesizer.set_appkey(appkey) synthesizer.set_token(token) synthesizer.set_voice(voice) synthesizer.set_text(text) synthesizer.set_format(TTSFormat.WAV) synthesizer.set_sample_rate(TTSSampleRate.SAMPLE_RATE_16K) synthesizer.set_volume(volumn) synthesizer.set_speech_rate(speech_rate) synthesizer.set_pitch_rate(pitch_rate) try: ret = synthesizer.start() if ret < 0: return ret synthesizer.wait_completed() except Exception as e: print(e) finally: synthesizer.close()
def text2sound(text, src="./t2s.wav", dst="./t2s_cnv.wav"): client = ali_speech.NlsClient() # set the level of output log information: DEBUG, INFO, WARNING, ERROR client.set_log_level('INFO') appkey = APPKEY token = TOKEN process(client, appkey, token, text, src) audio.upsample_wav(src=src, dst=dst, rate=44100)
def sound2text(src="s2t.wav", dst="s2t_cnv.wav"): audio.upsample_wav(src=src, dst=dst, rate=ASRSampleRate.SAMPLE_RATE_16K) client = ali_speech.NlsClient() # set the level of output log information: DEBUG, INFO, WARNING, ERROR client.set_log_level('INFO') appkey = APPKEY token = TOKEN process(client=client, appkey=appkey, token=token, src=dst) # multithread example # process_multithread(client, appkey, token, 2) return S2T_RESULT
def __init__(self): self.client = ali_speech.NlsClient() self.appkey = 'hPUZhaSWHkUp4NwM' self.AKID = 'LTAI4FyftcdsKMv6JcKcTvqv' self.AS = 'edjIOVArss0vPVSHKlJrjHh0XTwyHf' self.token = self.get_aliyun_secret() self.sound = [100, -100, 0] self.yin = [ ##通用场景## 'Xiaoyun', #0 'Ruoxi', 'Siqi', 'Sijia', 'Aiqi', 'Aijia', #1-5 'Ninger', 'Ruilin', #6,7 ##客服场景## 'Siyue', 'Aiya', 'Aimei', # 8-10 'Aiyu', 'Aiyue', 'Aijing', 'Xiaomei', 'Aina', #11-15 'Yina', 'Sijing', #16,17 ##儿童## 'Sitong', 'Xiaobei', 'Aitong', 'Aiwei', 'Aibao', #18-22 ##英语## 'Abby', 'Emily', 'Luna', 'Wendy', 'Olivia', #23-27 'Lydia', # 英中双语 ##方言## # 粤;川;台;东北 'Shanshan', 'Xiaoyue', 'Qingqing', 'Cuijie', #29-32 ] self.she = 'Aixia' # 声优 self.mode = 'ab' # 追加模式写入文件 self.sounds_dir = r'D:\#My\GiData\Creation\Projects\Python\Gina\GiFun\GHuman\sounds'
async def AddVoice(key: str) -> str: try: filepath = os.path.dirname(__file__) + '\data.txt' with open(filepath, "r") as fp: token = fp.read() t = time.time() filename = str(int(t)) + ".mp3" client = ali_speech.NlsClient() # 设置输出日志信息的级别:DEBUG、INFO、WARNING、ERROR client.set_log_level('INFO') appkey = 'Fx9voCGViOO6mKJj' text = key audio_name = 'data/record/record/' + filename process(client, appkey, token, text, audio_name) return "[CQ:record,file=record/" + filename + ",magic=false]" except (Exception): return ""
client = AcsClient("****", "****", "cn-shanghai") # 创建request,并设置参数。 request = CommonRequest() request.set_method('POST') request.set_domain('nls-meta.cn-shanghai.aliyuncs.com') request.set_version('2019-02-28') request.set_action_name('CreateToken') response = client.do_action_with_exception(request) print(response) if __name__ == "__main__": import time start_time = time.time() client = ali_speech.NlsClient() # 设置输出日志信息的级别:DEBUG、INFO、WARNING、ERROR。 client.set_log_level('INFO') appkey = '***' token = '***' text = "账单逾期请在今天内下载来分期诶皮皮查看并进行还款,关于您逾期的后果我已经跟您阐述清楚了,另外后续可能会到您当地法院控诉维权,到时给如果您个人生活以及如果您家人或同事查询到,对您声誉产生的所有后果影响由您个人承担,再见。" audio_name = './aliyun.wav' process(client, appkey, token, text, audio_name) # 多线程示例 # process_multithread(client, appkey, token, 2) print("time>>>>>>", time.time() - start_time) ''' f1 = open("./data/000001-010000.txt") lines = f1.readlines() for idx in range(0, len(lines), 2):
def toVoice(appkey, token, text, audio_name, voice): client = ali_speech.NlsClient() # 设置输出日志信息的级别:DEBUG、INFO、WARNING、ERROR client.set_log_level('INFO') process_multithread(client, appkey, token, text, audio_name, voice)