Spaces:
Running
Running
Download modules/utils/audio_manager.py from soiz1/Whisper-WebUI: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/soiz1/Whisper-WebUI/resolve/main/modules/utils/audio_manager.py
- Command line
-
hf download hf://spaces/soiz1/Whisper-WebUI/modules/utils/audio_manager.py
-
curl -L -o audio_manager.py https://huggingface.co/spaces/soiz1/Whisper-WebUI/resolve/main/modules/utils/audio_manager.py
1.08 kB
| from typing import Optional, Union | |
| import soundfile as sf | |
| import os | |
| import numpy as np | |
| from faster_whisper.audio import decode_audio | |
| from modules.utils.files_manager import is_video | |
| from modules.utils.logger import get_logger | |
| logger = get_logger() | |
| def validate_audio(audio: Optional[str] = None): | |
| """Validate audio file and check if it's corrupted""" | |
| if isinstance(audio, np.ndarray): | |
| return True | |
| if is_video(audio): | |
| try: | |
| audio = decode_audio(audio) | |
| return True | |
| except Exception as e: | |
| logger.info(f"The file {audio} is not able to open or corrupted. Please check the file. {e}") | |
| return False | |
| 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: | |
| logger.info(f"The file {audio} is not able to open or corrupted. Please check the file. {e}") | |
| return False | |