async def test_stop_audio_tts(): """测试停止所有正在播放的音频 先播放一段tts,3s后,停止所有所有音效,并等待结果 #StopAudioResponse.isSuccess : 是否成功 #StopAudioResponse.resultCode : 返回码 """ # 设置is_serial=False, 表示只需将指令发送给机器人,await不需要等机器人执行完结果再返回 block: StartPlayTTS = StartPlayTTS(is_serial=False, text="你让我说,让我说,不要打断我,不要打断我,不要打断我") response = await block.execute() print(f'test_stop_audio.play_tts: {response}') await asyncio.sleep(3) # 停止所有声音 block: StopAllAudio = StopAllAudio() (resultType, response) = await block.execute() print(f'test_stop_audio:{response}') block: StartPlayTTS = StartPlayTTS(text="第二次, 你让我说,让我说,不要打断我,不要打断我,不要打断我") asyncio.create_task(block.execute()) print(f'test_stop_audio.play_tts: {response}') await asyncio.sleep(3) assert resultType == MiniApiResultType.Success, 'test_stop_audio timetout' assert response is not None and isinstance( response, StopAudioResponse), 'test_stop_audio result unavailable' assert response.isSuccess, 'test_stop_audio failed'
async def test_stop_play_tts(): """测试停止播放tts 使机器人开始播放一段长文本tts,内容为"你好, 我是悟空, 啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦",不等待结果 2s后,使机器人停止播放tts #ControlTTSResponse.isSuccess : 是否成功 #ControlTTSResponse.resultCode : 返回码 """ # is_serial:串行执行 # text:要合成的文本 block: StartPlayTTS = StartPlayTTS( is_serial=False, text="你好, 我是悟空, 啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦") # 返回bool 表示是否发送成功 await block.execute() await asyncio.sleep(2) (resultType, response) = await StopPlayTTS().execute() print(f'test_stop_play_tts result: {response}') # StopPlayTTS block的response包含resultCode和isSuccess # 如果resultCode !=0 可以通过errors.get_speech_error_str(response.resultCode)) 查询错误描述信息 print('resultCode = {0}, error = {1}'.format( response.resultCode, errors.get_speech_error_str(response.resultCode))) assert resultType == MiniApiResultType.Success, 'test_stop_play_tts timetout' assert response is not None and isinstance( response, ControlTTSResponse), 'test_stop_play_tts result unavailable' assert response.isSuccess, 'test_stop_play_tts failed'
async def test_play_tts(): """测试播放tts 使机器人开始播放一段tts,内容为"你好, 我是悟空, 啦啦啦",并等待结果 #ControlTTSResponse.isSuccess : 是否成功 #ControlTTSResponse.resultCode : 返回码 """ # is_serial:串行执行 # text:要合成的文本 block: StartPlayTTS = StartPlayTTS(text="你好, 我是悟空, 啦啦啦") # 返回元组, response是个ControlTTSResponse (resultType, response) = await block.execute() print(f'test_play_tts result: {response}') # StartPlayTTS block的response包含resultCode和isSuccess # 如果resultCode !=0 可以通过errors.get_speech_error_str(response.resultCode)) 查询错误描述信息 print('resultCode = {0}, error = {1}'.format( response.resultCode, errors.get_speech_error_str(response.resultCode))) assert resultType == MiniApiResultType.Success, 'test_play_tts timetout' assert response is not None and isinstance( response, ControlTTSResponse), 'test_play_tts result unavailable' assert response.isSuccess, 'test_play_tts failed'
async def say(self, **kwargs): self._ensure_connect() block: StartPlayTTS = StartPlayTTS(**kwargs) # 返回元组, response是个ControlTTSResponse (resultType, response) = await block.execute()
async def __tts(): block: StartPlayTTS = StartPlayTTS(text="你好, 我是悟空, 啦里啦,啦里啦") response = await block.execute() print(f'tes_play_tts: {response}')
async def _play_tts(): block: StartPlayTTS = StartPlayTTS(text="你好, 我是悟空,测试测试,啦啦啦") # 返回元组, response是个ControlTTSResponse (resultType, response) = await block.execute() print(f'{response}')