async def test_play_tts3(): # control_type: TTSControlType.START: 播放tts; TTSControlType.STOP: 停止tts #block3: PlayTTS = PlayTTS(text="伤心伤心伤心伤心伤心伤心", control_type=TTSControlType.START) block: PlayTTS = PlayTTS(text="别伤心啦,我给你讲个笑话吧", control_type=TTSControlType.START) block1: PlayTTS = PlayTTS(text="妈妈,老鼠跳进咱家那奶桶里了!哎呀!你把它捉出来了吗?没有,但我把咱的猫放进去了", control_type=TTSControlType.START) block2: PlayTTS = PlayTTS(text="怎么样,心情好点了吗", control_type=TTSControlType.START) # 返回元组, response是个ControlTTSResponse #(resultType, response) = await block3.execute() (resultType, response) = await block.execute() (resultType, response) = await block1.execute() await asyncio.sleep(8) (resultType, response) = await block2.execute() print(f'test_play_tts result: {response}') # PlayTTS 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 test_stop_audio_tts(): """测试停止所有正在播放的音频 先播放一段tts,3s后,停止所有所有音效,并等待结果 #StopAudioResponse.isSuccess : 是否成功 #StopAudioResponse.resultCode : 返回码 """ # 设置is_serial=False, 表示只需将指令发送给机器人,await不需要等机器人执行完结果再返回 block: PlayTTS = PlayTTS(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}') 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 play_tts(): block: PlayTTS = PlayTTS(text="你好, 我是悟空,测试测试,啦啦啦", control_type=TTSControlType.START) # 返回元组, response是个ControlTTSResponse (resultType, response) = await block.execute() 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 test_play_tts4(): # control_type: TTSControlType.START: 播放tts; TTSControlType.STOP: 停止tts #block2: PlayTTS = PlayTTS(text="请站起来站起来吧请站起来站起来吧请站起来站起来吧", control_type=TTSControlType.START) block: PlayTTS = PlayTTS(text="坐了这么久,是该站起来活动一下了", control_type=TTSControlType.START) block1: PlayTTS = PlayTTS(text="甩甩手吧", control_type=TTSControlType.START) # 返回元组, response是个ControlTTSResponse #(resultType, response) = await block2.execute() (resultType, response) = await block.execute() (resultType, response) = await block1.execute() print(f'test_play_tts result: {response}') # PlayTTS 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 test_play_tts(): """测试播放tts 使机器人开始播放一段tts,内容为"你好, 我是悟空, 啦啦啦",并等待结果 control_type可选TTSControlType.START/TTSControlType.STOP #ControlTTSResponse.isSuccess : 是否成功 #ControlTTSResponse.resultCode : 返回码 """ # is_serial:串行执行 # text:要合成的文本 # control_type: TTSControlType.START: 播放tts; TTSControlType.STOP: 停止tts block: PlayTTS = PlayTTS(text="你好,我们是你的新朋友,你可以叫我悟空,这是我的朋友Tony", control_type=TTSControlType.START) block1: PlayTTS = PlayTTS(text="你可以试着对我们做个表情或动作", control_type=TTSControlType.START) # 返回元组, response是个ControlTTSResponse (resultType, response) = await block.execute() await asyncio.sleep(3) (resultType, response) = await block1.execute() #await asyncio.sleep(2) print(f'test_play_tts result: {response}') # PlayTTS 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 test_play_tts5(): # control_type: TTSControlType.START: 播放tts; TTSControlType.STOP: 停止tts block: PlayTTS = PlayTTS(text="做的真棒,我们也来做一个", control_type=TTSControlType.START) await asyncio.sleep(3) # 返回元组, response是个ControlTTSResponse (resultType, response) = await block.execute() print(f'test_play_tts result: {response}') # PlayTTS 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 __tts(): block: PlayTTS = PlayTTS(text="你好, 我是悟空, 啦里啦,啦里啦") response = await block.execute() print(f'tes_play_tts: {response}')