Spaces:
Running on Zero
Running on Zero
Download validation.py from Edge0/Audio8-TTS-Realistic-Air: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/spaces/Edge0/Audio8-TTS-Realistic-Air/resolve/main/validation.py
- Command line
-
hf download hf://spaces/Edge0/Audio8-TTS-Realistic-Air/validation.py
-
curl -L -o validation.py https://huggingface.co/spaces/Edge0/Audio8-TTS-Realistic-Air/resolve/main/validation.py
1.7 kB
| """Validate interactive inputs on CPU before reserving any GPU time.""" | |
| from pathlib import Path | |
| MAX_FILE_BYTES = 15 * 1024 * 1024 | |
| MAX_TEXT_CHARS = 600 | |
| MAX_TRANSCRIPT_CHARS = 600 | |
| def validate_request(text, reference_path, reference_text): | |
| if not isinstance(text, str) or not text.strip(): | |
| raise ValueError('Please enter the text you want to hear.') | |
| text = text.strip() | |
| if len(text) > MAX_TEXT_CHARS: | |
| raise ValueError('Please keep the target text to 600 characters or fewer.') | |
| if not reference_path: | |
| raise ValueError('Choose a reference voice or upload a recording.') | |
| if not isinstance(reference_text, str) or not reference_text.strip(): | |
| raise ValueError('Please enter the exact words spoken in your reference recording.') | |
| reference_text = reference_text.strip() | |
| if len(reference_text) > MAX_TRANSCRIPT_CHARS: | |
| raise ValueError('Please keep the reference transcript to 600 characters or fewer.') | |
| path = Path(reference_path) | |
| if not path.is_file() or path.stat().st_size > MAX_FILE_BYTES: | |
| raise ValueError('Please upload an audio file smaller than 15 MB.') | |
| import soundfile as sf | |
| try: | |
| info = sf.info(path) | |
| except (RuntimeError, OSError): | |
| raise ValueError('The reference could not be read. Try a WAV, MP3 or FLAC recording.') from None | |
| if not (3 <= info.duration <= 15): | |
| raise ValueError('Please use a reference recording between 3 and 15 seconds.') | |
| if not (8000 <= info.samplerate <= 192000) or info.channels not in {1, 2}: | |
| raise ValueError('Please upload a mono or stereo recording with a standard audio sample rate.') | |
| return text, str(path), reference_text | |