Skip to content

Commit

Permalink
use gr.Error for audio length errors (#6672)
Browse files Browse the repository at this point in the history
* use gr.Error for audio length errors

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
abidlabs and gradio-pr-bot committed Dec 5, 2023
1 parent 299f5e2 commit 1234c37
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 1234c37

Please sign in to comment.