File size: 1,323 Bytes
e904efb
38dbcc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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