Spaces:
Runtime error
Runtime error
Download app.py from Clearwave48/denoiser-api: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/Clearwave48/denoiser-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/Clearwave48/denoiser-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Clearwave48/denoiser-api/resolve/main/app.py
1.32 kB
| import os | |
| import requests | |
| import subprocess | |
| import re | |
| class Denoiser: | |
| def __init__(self): | |
| self.api_key = os.environ.get("CLEANVOICE_API_KEY","") | |
| def process(self, audio_path, out_dir, **kwargs): | |
| # Pre-convert to WAV to ensure the API never fails on AAC/Opus | |
| standard_wav = os.path.join(out_dir, "internal_process.wav") | |
| subprocess.run(["ffmpeg", "-y", "-i", audio_path, "-ar", "16000", "-ac", "1", standard_wav], capture_output=True) | |
| try: | |
| from cleanvoice import Cleanvoice | |
| cv = Cleanvoice({'api_key': self.api_key}) | |
| result = cv.process(standard_wav, remove_noise=True, studio_sound=True, **kwargs) | |
| audio_data = requests.get(result.audio.url).content | |
| clean_wav = os.path.join(out_dir, "clean_internal.wav") | |
| with open(clean_wav, "wb") as f: | |
| f.write(audio_data) | |
| return {'audio_path': clean_wav} | |
| except Exception: | |
| return {'audio_path': standard_wav} | |
| def clean_transcript_fillers(self, text): | |
| fillers = r'\b(um|uh|hmm|basically|like|ante|ane|matlab)\b' | |
| return re.sub(fillers, '', text, flags=re.IGNORECASE).strip() | |
| def _remove_fillers(self, a, s, seg): return a, 0 | |
| def _remove_stutters(self, a, s, seg): return a, 0 |