Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions astrbot/core/utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ async def ensure_wav(audio_path: str, output_path: str | None = None) -> str:
if not audio_path:
return audio_path

if not os.path.exists(audio_path):
# File not available yet (e.g. napcat race condition);
# return the path as-is so upstream retry logic can handle it later.
return audio_path
Comment on lines +254 to +257
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If audio_path is a remote URL (e.g., starting with http), os.path.exists(audio_path) will return False. This causes ensure_wav to return the URL as-is, bypassing the conversion to a local WAV file. This breaks the expected behavior where remote audio URLs are downloaded and converted to local WAV files.

We should only return early if the path is a local path and does not exist.

Suggested change
if not os.path.exists(audio_path):
# File not available yet (e.g. napcat race condition);
# return the path as-is so upstream retry logic can handle it later.
return audio_path
if not audio_path.startswith("http") and not os.path.exists(audio_path):
# File not available yet (e.g. napcat race condition);
# return the path as-is so upstream retry logic can handle it later.
return audio_path


audio_type = _get_audio_magic_type(audio_path)
if audio_type == "wav":
return audio_path
Expand Down
Loading