Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use gr.Error for audio length errors #6672

Merged
merged 3 commits into from Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eager-snakes-boil.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:use gr.Error for audio length errors
5 changes: 3 additions & 2 deletions gradio/components/audio.py
Expand Up @@ -15,6 +15,7 @@
from gradio.components.base import Component, StreamingInput, StreamingOutput
from gradio.data_classes import FileData
from gradio.events import Events
from gradio.exceptions import Error

set_documentation_group("component")

Expand Down Expand Up @@ -190,11 +191,11 @@ def preprocess(

duration = len(data) / sample_rate
if self.min_length is not None and duration < self.min_length:
raise ValueError(
raise Error(
f"Audio is too short, and must be at least {self.min_length} seconds"
)
if self.max_length is not None and duration > self.max_length:
raise ValueError(
raise Error(
f"Audio is too long, and must be at most {self.max_length} seconds"
)

Expand Down