Skip to content

Commit

Permalink
improve logging for large audio files
Browse files Browse the repository at this point in the history
  • Loading branch information
n3d1117 committed Mar 18, 2023
1 parent 13a3740 commit f7bb416
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions telegram_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,17 @@ async def transcribe(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
filename = update.message.effective_attachment.file_unique_id
filename_mp3 = f'{filename}.mp3'

media_file = await context.bot.get_file(update.message.effective_attachment.file_id)
await media_file.download_to_drive(filename)
try:
media_file = await context.bot.get_file(update.message.effective_attachment.file_id)
await media_file.download_to_drive(filename)
except Exception as e:
logging.exception(e)
await context.bot.send_message(
chat_id=chat_id,
reply_to_message_id=update.message.message_id,
text=f'Failed to download audio file: {str(e)}'
)
return

# detect and extract audio from the attachment with pydub
try:
Expand All @@ -177,7 +186,7 @@ async def transcribe(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
logging.info(f'New transcribe request received from user {update.message.from_user.name}')

except Exception as e:
logging.info(f'Unsupported file type recceived from {update.message.from_user.name}')
logging.exception(e)
await context.bot.send_message(
chat_id=update.effective_chat.id,
reply_to_message_id=update.message.message_id,
Expand Down

0 comments on commit f7bb416

Please sign in to comment.