-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
def get_wav():
try:
# 获取用户标识(例如,通过POST请求中的JSON数据)
data = request.json
user = data.get('user', 'User')
# 通过HTTP GET请求从指定地址获取最新数据
course_id = data.get('course_id', 1164)
headers = {
'easegen-api-key': 'ak_SzEhMFPTKjIQBhGVmkle'
}
response = requests.get(
"http://36.103.251.108:48080/admin-api/digitalcourse/courses/getCourseText",
params={
'course_id': course_id,
},
headers=headers,
timeout=10
)
# 检查请求是否成功
if response.status_code == 200:
response_data = response.json()
if response_data.get('code') == 0:
data = response_data.get('data', {})
audio = data.get('audio', '')
text = data.get('text', '')
timestamp = data.get('timestamp', int(time.time()))
img = data.get('img', '')
# 显示图像
if img:
display_image(img)
# 返回的JSON响应
return jsonify({
'audio': audio,
'text': text,
'timestamp': timestamp
})
else:
return jsonify({'error': '获取数据失败'}), 500
else:
return jsonify({'error': '请求失败'}), 500
except requests.exceptions.Timeout:
return jsonify({'error': '请求超时'}), 500
except requests.exceptions.RequestException as e:
return jsonify({'error': f'请求出现异常: {str(e)}'}), 500
get_wav函数中url访问超时该如何解决呢
Metadata
Metadata
Assignees
Labels
No labels