Skip to content

Commit e6ab4c3

Browse files
authored
fix(load): clear FileNotFoundError for missing audio path (#2981)
When an audio file path did not exist, load_audio_text_image_video silently passed the raw string downstream, crashing later with a cryptic "expected Tensor as element 1 in argument 0, but got str" deep inside the VAD. New users following the README quickstart (placeholder meeting.wav) hit this confusing internal error. Now raise a clear FileNotFoundError naming the missing path. Scoped to data_type=sound so text inputs are unaffected. Tested: missing path -> FileNotFoundError with helpful message; valid path -> unchanged. Co-authored-by: LauraGPT <LauraGPT@users.noreply.github.com>
1 parent faffb45 commit e6ab4c3

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

funasr/utils/load_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ def load_audio_text_image_video(
9797
): # download url to local file
9898
data_or_path_or_list = download_from_url(data_or_path_or_list)
9999

100+
# Fail fast with a clear error if an audio file path does not exist, instead of
101+
# silently passing the string downstream (which later crashes with a cryptic
102+
# "expected Tensor ... but got str" deep inside the model).
103+
if (
104+
isinstance(data_or_path_or_list, str)
105+
and data_type in (None, "sound")
106+
and not data_or_path_or_list.startswith(("http://", "https://"))
107+
and not os.path.exists(data_or_path_or_list)
108+
):
109+
raise FileNotFoundError(
110+
f"Audio file not found: {data_or_path_or_list!r}. Pass a valid local file "
111+
f"path, URL, numpy array, torch.Tensor, or bytes."
112+
)
100113
if (isinstance(data_or_path_or_list, str) and os.path.exists(data_or_path_or_list)) or hasattr(data_or_path_or_list, 'read'): # local file or bytes io
101114
if data_type is None or data_type == "sound":
102115
if hasattr(data_or_path_or_list, "read") and hasattr(data_or_path_or_list, "seek"):

0 commit comments

Comments
 (0)