use gr.Error for audio length errors (#6672)

* use gr.Error for audio length errors

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Abubakar Abid 2023-12-05 13:15:16 -08:00 committed by GitHub
parent 299f5e238b
commit 1234c3732b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:use gr.Error for audio length errors

View File

@ -15,6 +15,7 @@ from gradio import processing_utils, utils
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")
@ -190,11 +191,11 @@ class Audio(
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"
)