-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #471 from jhj0517/fix/handle-silent-audio
Leave a message for corrupted audio instead of raising error
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from typing import Optional, Union | ||
import soundfile as sf | ||
import os | ||
import numpy as np | ||
|
||
|
||
def validate_audio(audio: Optional[str] = None): | ||
"""Validate audio file and check if it's corrupted""" | ||
if isinstance(audio, np.ndarray): | ||
return True | ||
|
||
if not os.path.exists(audio): | ||
return False | ||
|
||
try: | ||
with sf.SoundFile(audio) as f: | ||
if f.frames > 0: | ||
return True | ||
else: | ||
return False | ||
except Exception as e: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters