import requests import json import time start_time = time.time() # Flask API的URL api_url = 'http://122.51.206.54:4800/asr' # 要识别的音频文件的URL # audio_url = 'https://cm-1255337128.cos.ap-guangzhou.myqcloud.com/asr-service/Chinese.wav' audio_url = 'https://cm-1255337128.cos.ap-guangzhou.myqcloud.com/asr-service/English.wav' # audio_url = 'https://cm-1255337128.cos.ap-guangzhou.myqcloud.com/asr-service/Cantonese.wav' # audio_url = 'https://cm-1255337128.cos.ap-guangzhou.myqcloud.com/asr-service/20241213-8akzhpov.wav' # 构造请求数据 data = { 'audio_url': audio_url } # 发送POST请求 headers = {'Content-Type': 'application/json'} response = requests.post(api_url, data=json.dumps(data), headers=headers) # 处理响应 if response.status_code == 200: result = response.json() # 假设返回的结果中包含一个'predictions'键,其值是一个包含识别结果的列表 for prediction in result['predictions']: print('Recognized Text:', prediction['text']) else: print('Error:', response.json()) end_time = time.time() elapsed_time = end_time - start_time print(f"代码块运行时长: {elapsed_time:.6f} 秒")