Skip to content

Commit

Permalink
v0.07.7 - whisper logging
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingFathead committed Apr 1, 2024
1 parent 39a807b commit 9538665
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ After launching the bot, you can interact with it via Telegram:

## Changes

- v0.07.7 - log output from `whisper` to logging
- v0.07.6 - update interval for logging `yt-dlp` downloads now configurable from `config.ini`
- v0.07.5 - 10-second interval update for `yt-dlp` logging
- v0.07.4 - fixes for non-youtube urls
Expand Down
2 changes: 1 addition & 1 deletion 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.07.6"
version_number = "0.07.7"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# https://github.com/FlyingFathead/whisper-transcriber-telegram-bot/
Expand Down
31 changes: 27 additions & 4 deletions src/transcription_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# transcription_handler.py
# ~~~
# openai-whisper transcriber-bot for Telegram
# v0.07.6
# v0.07.7
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# https://github.com/FlyingFathead/whisper-transcriber-telegram-bot/
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -170,6 +170,23 @@ async def download_audio(url, output_path):
else:
logger.error(f"Failed to download audio: {output_path}")

# Read from stream line by line until EOF, call callback on each line.
async def read_stream(stream, callback):
while True:
line = await stream.readline()
if line:
callback(line.decode())
else:
break

# Log each line from the stdout.
def log_stdout(line):
logger.info(f"Whisper stdout: {line.strip()}")

# Log each line from the stderr.
def log_stderr(line):
logger.error(f"Whisper stderr: {line.strip()}")

# transcription logic with header inclusion based on settings
async def transcribe_audio(audio_path, output_dir, youtube_url, video_info_message, include_header):

Expand All @@ -180,18 +197,24 @@ async def transcribe_audio(audio_path, output_dir, youtube_url, video_info_messa

transcription_command = ["whisper", audio_path, "--model", model, "--output_dir", output_dir]

# Start the subprocess and get stdout, stderr streams
process = await asyncio.create_subprocess_exec(
*transcription_command,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)

stdout, stderr = await process.communicate()
# Concurrently log stdout and stderr
await asyncio.gather(
read_stream(process.stdout, log_stdout),
read_stream(process.stderr, log_stderr)
)

# Wait for the subprocess to finish
await process.wait()

# Check if Whisper process encountered an error
if process.returncode != 0:
logger.error(f"Whisper process failed with return code {process.returncode}")
logger.error(f"Whisper STDERR: {stderr.decode()}")
return {}

logger.info(f"Whisper transcription completed for: {audio_path}")
Expand Down

0 comments on commit 9538665

Please sign in to comment.