Skip to content

Commit

Permalink
修复睿声调用,音频后缀名改为mp3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Jun 27, 2024
1 parent 96837fe commit faa8ca5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@ async def audio_synthesis_use_local_config(self, content, audio_synthesis_type="
voice_tmp_path = self.my_tts.openai_tts_api(data)

elif audio_synthesis_type == "reecho_ai":
data = content
# 调用接口合成语音
voice_tmp_path = await self.my_tts.reecho_ai_api(data)

Expand Down
8 changes: 4 additions & 4 deletions utils/audio_handle/my_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def encode_audio_to_base64(self, file_path):
encoded_audio = base64.b64encode(audio_data).decode('utf-8')
return encoded_audio

async def download_audio(self, type: str, file_url: str, timeout: int=30, request_type: str="get", data=None, json_data=None):
async def download_audio(self, type: str, file_url: str, timeout: int=30, request_type: str="get", data=None, json_data=None, audio_suffix: str="wav"):
async with aiohttp.ClientSession() as session:
try:
if request_type == "get":
async with session.get(file_url, params=data, timeout=timeout) as response:
if response.status == 200:
content = await response.read()
file_name = type + '_' + self.common.get_bj_time(4) + '.wav'
file_name = type + '_' + self.common.get_bj_time(4) + '.' + audio_suffix
voice_tmp_path = self.common.get_new_audio_path(self.audio_out_path, file_name)
with open(voice_tmp_path, 'wb') as file:
file.write(content)
Expand All @@ -87,7 +87,7 @@ async def download_audio(self, type: str, file_url: str, timeout: int=30, reques
async with session.post(file_url, data=data, json=json_data, timeout=timeout) as response:
if response.status == 200:
content = await response.read()
file_name = type + '_' + self.common.get_bj_time(4) + '.wav'
file_name = type + '_' + self.common.get_bj_time(4) + '.' + audio_suffix
voice_tmp_path = self.common.get_new_audio_path(self.audio_out_path, file_name)
with open(voice_tmp_path, 'wb') as file:
file.write(content)
Expand Down Expand Up @@ -538,7 +538,7 @@ async def reecho_ai_api(self, text):

url = ret["data"]["audio"]

return await self.download_audio("reecho.ai", url, self.timeout, "get", None)
return await self.download_audio("reecho.ai", url, self.timeout, "get", None, audio_suffix="mp3")

except aiohttp.ClientError as e:
logger.error(f'reecho.ai请求失败: {e}')
Expand Down
21 changes: 16 additions & 5 deletions utils/gpt_model/zhipu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ def __init__(self, data):

self.config_data = data

# 判断zhipu库版本,1.x.x和2.x.x有破坏性更新
if version.parse(zhipuai.__version__) < version.parse('2.0.0'):
zhipuai.api_key = data["api_key"]
else:
# zhipuai库版本
self.zhipuai_ver = "2.0.0"

try:
# 判断zhipu库版本,1.x.x和2.x.x有破坏性更新
if version.parse(zhipuai.__version__) < version.parse('2.0.0'):
self.zhipuai_ver = "1.0.0"
zhipuai.api_key = data["api_key"]
else:
self.zhipuai_ver = zhipuai.__version__
from zhipuai import ZhipuAI
self.client = ZhipuAI(api_key=data["api_key"])
except Exception as e:
self.zhipuai_ver = "1.0.0"
from zhipuai import ZhipuAI
self.client = ZhipuAI(api_key=data["api_key"])

Expand Down Expand Up @@ -223,7 +233,7 @@ def get_resp(self, prompt):
str: 返回的文本回答
"""
try:
if version.parse(zhipuai.__version__) < version.parse('2.0.0'):
if version.parse(self.zhipuai_ver) < version.parse('2.0.0'):
if self.config_data["history_enable"]:
self.history.append({"role": "user", "content": prompt})
data_json = self.history
Expand Down Expand Up @@ -435,6 +445,7 @@ def is_odd(number):
logger.error(traceback.format_exc())
return None

# 图像识别模型调用,需要zhipuai库大于1.x.x
def get_resp_with_img(self, prompt, img_data):
try:
# 检查 img_data 的类型
Expand Down

0 comments on commit faa8ca5

Please sign in to comment.