refactor: update translation script to support generic audio stream U…#24
Conversation
…RLs instead of YouTube-specific extraction
There was a problem hiding this comment.
Code Review
This pull request refactors the real-time translation CLI tool to stream and translate generic remote audio URLs instead of being restricted to YouTube videos. It removes the dependency on yt_dlp and updates the command-line arguments, making the --url parameter optional with a default sample audio file. Feedback suggests wrapping the ffmpeg subprocess execution in a try-except block to gracefully handle cases where ffmpeg is not installed on the user's system, preventing a cryptic crash.
| return | ||
|
|
||
| print("[Info] Starting audio stream via ffmpeg...") | ||
| async def stream_audio_url(url: str, audio_queue: asyncio.Queue, original_playback_queue: asyncio.Queue = None, volume: float = 0.08): |
There was a problem hiding this comment.
If ffmpeg is not installed on the user's system, asyncio.create_subprocess_exec will raise a FileNotFoundError (or OSError), which will propagate and crash the application with a cryptic error message.
To improve the user experience, consider wrapping the subprocess creation in a try-except block and raising a more descriptive RuntimeError that guides the user to install ffmpeg.
For example:
try:
process = await asyncio.create_subprocess_exec(
'ffmpeg',
'-i', url,
'-f', 's16le',
'-acodec', 'pcm_s16le',
'-ar', str(SEND_SAMPLE_RATE),
'-ac', str(CHANNELS),
'-',
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.DEVNULL
)
except OSError as e:
raise RuntimeError(
f"Failed to start ffmpeg ({e}). Please ensure ffmpeg is installed and available in your PATH."
)
…RLs instead of YouTube-specific extraction