Skip to content

Commit

Permalink
v0.14.1 - file handling tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingFathead committed Jun 1, 2024
1 parent b09cd3c commit 89861e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ After launching the bot, you can interact with it via Telegram:

## Changes

- v0.14.1 - small fixes to the file handler; more detailed exception catching
- v0.14 - now handles both Telegram's audio messages as well as audio files (.wav, .mp3)
- v0.13 - added `GPUtil` GPU mapping to figure out the best available CUDA GPU instance to use
- (by default, uses a CUDA-enabled GPU on the system with the most free VRAM available)
Expand Down
13 changes: 9 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# openai-whisper transcriber-bot for Telegram

# version of this program
version_number = "0.14"
version_number = "0.14.1"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# https://github.com/FlyingFathead/whisper-transcriber-telegram-bot/
Expand Down Expand Up @@ -110,7 +110,6 @@ async def handle_message(self, update: Update, context: CallbackContext) -> None
# await process_url_message(message_text, bot, update, model)
# self.task_queue.task_done()


async def process_queue(self):
while True:
task, bot, update = await self.task_queue.get()
Expand All @@ -125,6 +124,7 @@ async def process_queue(self):
await process_url_message(task, bot, update, model)
elif task.endswith('.wav') or task.endswith('.mp3'):
logger.info(f"Processing audio file: {task}")

# Notify the user about the model and GPU
await bot.send_message(chat_id=update.effective_chat.id, text=f"Starting transcription with model: {model}")
best_gpu = get_best_gpu()
Expand Down Expand Up @@ -172,7 +172,7 @@ async def process_queue(self):
logger.info(detailed_message)
await bot.send_message(chat_id=update.effective_chat.id, text=detailed_message)

# Transcribe the audio
# Now start the transcription process
transcription_paths = await transcribe_audio(task, self.output_dir, "", "", self.config.getboolean('TranscriptionSettings', 'includeheaderintranscription'), model, device)
if not transcription_paths:
# Notify if transcription fails
Expand All @@ -183,7 +183,12 @@ async def process_queue(self):

# Send transcription files and finalize the process
for fmt, path in transcription_paths.items():
await bot.send_document(chat_id=update.effective_chat.id, document=open(path, 'rb'))
try:
await bot.send_document(chat_id=update.effective_chat.id, document=open(path, 'rb'))
logger.info(f"Sent {fmt} file to user {user_id}: {path}")
except Exception as e:
logger.error(f"Failed to send {fmt} file to user {user_id}: {path}, error: {e}")

if not self.config.getboolean('TranscriptionSettings', 'keepaudiofiles'):
os.remove(task)

Expand Down

0 comments on commit 89861e0

Please sign in to comment.