修复:语音问题

This commit is contained in:
Wuyi无疑 2022-04-26 23:13:42 +08:00
parent ae0c66b056
commit 525c6791f9

View File

@ -129,7 +129,7 @@ food_im = """【{}】
材料 材料
{}""" {}"""
audio_json = """{ audio_json = {
'357': ['357_01', '357_02', '357_03'], '357': ['357_01', '357_02', '357_03'],
'1000000': ['1000000_01', '1000000_02', '1000000_03', '1000000_04', '1000000_05', '1000000_06', '1000000_07'], '1000000': ['1000000_01', '1000000_02', '1000000_03', '1000000_04', '1000000_05', '1000000_06', '1000000_07'],
'1000001': ['1000001_01', '1000001_02', '1000001_03'], '1000001': ['1000001_01', '1000001_02', '1000001_03'],
@ -149,7 +149,7 @@ audio_json = """{
'1010301':['1010301_01','1010301_02','1010301_03','1010301_04','1010301_05'], '1010301':['1010301_01','1010301_02','1010301_03','1010301_04','1010301_05'],
'1010400':['1010400_01','1010400_02','1010400_03'], '1010400':['1010400_01','1010400_02','1010400_03'],
'1020000':['1020000_01'] '1020000':['1020000_01']
}""" }
char_adv_im = """{} char_adv_im = """{}
五星武器{} 五星武器{}
@ -308,36 +308,38 @@ async def award(uid):
async def audio_wiki(name, message): async def audio_wiki(name, message):
async def get(_audioid): async def get(_audioid):
tmp_json = json.loads(audio_json)
for _ in range(3): # 重试3次 for _ in range(3): # 重试3次
if _audioid in tmp_json: if _audioid in audio_json:
if not tmp_json[_audioid]: if not audio_json[_audioid]:
return return
audioid1 = random.choice(tmp_json[_audioid]) audioid1 = random.choice(audio_json[_audioid])
else: else:
audioid1 = _audioid audioid1 = _audioid
url = await get_audio_info(name, audioid1) url = await get_audio_info(name, audioid1)
req = requests.get(url) async with AsyncClient() as client:
req = await client.get(url)
if req.status_code == 200: if req.status_code == 200:
return BytesIO(req.content) return BytesIO(req.content)
else: else:
if _audioid in tmp_json: if _audioid in audio_json:
tmp_json[_audioid].remove(audioid1) audio_json[_audioid].remove(audioid1)
if name == '列表': if name == '列表':
imgmes = 'base64://' + b64encode(open(os.path.join(INDEX_PATH, '语音.png'), 'rb').read()).decode() with open(os.path.join(INDEX_PATH, '语音.png'), 'rb') as f:
imgmes = f.read()
return imgmes return imgmes
elif name == '': elif name == '':
return '请输入角色名。' return '请输入角色名。'
else: else:
audioid = re.findall(r'[0-9]+', message)[0] audioid = re.findall(r'\d+', message)
try: try:
audio = await get(audioid) audio = await get(audioid[0])
except IndexError:
return '请输入语音ID。'
except: except:
return '语音获取失败' return '语音获取失败'
if audio: if audio:
audios = 'base64://' + b64encode(audio.getvalue()).decode() return audio.getvalue()
return audios
else: else:
return '没有找到语音请检查语音ID与角色名是否正确如无误则可能未收录该语音' return '没有找到语音请检查语音ID与角色名是否正确如无误则可能未收录该语音'