Skip to content

Commit

Permalink
🐛 Bug: Fix undefined title bug.
Browse files Browse the repository at this point in the history
💻 Code: Remove pydub dependency.
  • Loading branch information
yym68686 committed Jul 23, 2024
1 parent 98e7288 commit 7b79c9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 6 additions & 6 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ async def handle_file(update, context):
message = await context.bot.send_message(chat_id=chatid, message_thread_id=message_thread_id, text=escape(strings['message_doc'][get_current_lang()]), parse_mode='MarkdownV2', disable_web_page_preview=True)
await delete_message(update, context, [message.message_id])

from pydub import AudioSegment
from io import BytesIO
async def transcribe_audio(file_id: str, bot) -> str:
file_unique_id = file_id
Expand All @@ -482,17 +481,17 @@ async def transcribe_audio(file_id: str, bot) -> str:
file = await bot.get_file(file_id)
file_bytes = await file.download_as_bytearray()

audio = AudioSegment.from_file(BytesIO(file_bytes))
audio.export(filename_mp3, format="mp3")
# 创建一个字节流对象
audio_stream = BytesIO(file_bytes)

with open(filename_mp3, 'rb') as audio_file:
transcript = config.whisperBot.generate(audio_file)
# 直接使用字节流对象进行转录
transcript = config.whisperBot.generate(audio_stream)

return transcript

except Exception as e:
logging.exception(e)
return f"Ошибка при обработке аудиофайла: {str(e)}"
return f"处理音频文件时出错: {str(e)}"
finally:
import os
if os.path.exists(filename_mp3):
Expand All @@ -511,6 +510,7 @@ async def handle_voice(update, context):
_, _, _, chatid, messageid, _, _, message_thread_id, convo_id, file_url, _ = await GetMesageInfo(update, context)
engine = get_ENGINE(convo_id)
robot, role = get_robot(convo_id)
title = ""
if Users.get_config(convo_id, "TITLE"):
title = f"`🤖️ {engine}`\n\n"
if Users.get_config(convo_id, "REPLY") == False:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ python-telegram-bot[webhooks,rate-limiter]==21.0.1

lxml
pytz
pydub
PyExecJS
requests
pdfminer.six
Expand Down

0 comments on commit 7b79c9a

Please sign in to comment.