testingfaces commited on
Commit
d6ceeb6
Β·
verified Β·
1 Parent(s): 1e542e4

Update denoiser.py

Browse files
Files changed (1) hide show
  1. denoiser.py +28 -18
denoiser.py CHANGED
@@ -1,18 +1,19 @@
1
  """
2
  Department 1 β€” Cloud Denoiser (Cleanvoice API)
3
- The "Vacuum-Sealed" Podcast Sound
4
  """
5
  import os
6
  import requests
7
  import tempfile
8
  import logging
9
  import re
 
10
 
11
  logger = logging.getLogger(__name__)
12
 
13
  class Denoiser:
14
  def __init__(self):
15
- # ⚠️ PASTE YOUR API KEY RIGHT HERE! ⚠️
16
  self.api_key = "cvk_Xnmz7ZPXMRg.CcE3YGry3IzkCBWQKGvomBfd9hmC9L-aAvSj-2iNfyw"
17
  print("[Denoiser] ☁️ Cleanvoice Cloud API loaded")
18
 
@@ -27,9 +28,6 @@ class Denoiser:
27
  from cleanvoice import Cleanvoice
28
  except ImportError:
29
  raise RuntimeError("Please add cleanvoice-sdk to your requirements.txt")
30
-
31
- if self.api_key == "YOUR_CLEANVOICE_API_KEY_HERE":
32
- raise ValueError("You need to paste your Cleanvoice API key into denoiser.py!")
33
 
34
  cv = Cleanvoice({'api_key': self.api_key})
35
 
@@ -46,28 +44,40 @@ class Denoiser:
46
  breath=remove_breaths
47
  )
48
 
49
- logger.info(f"[Denoiser] Cloud processing complete. Downloading result...")
50
-
51
- fd, final_audio_path = tempfile.mkstemp(suffix="_cv_cleaned.wav", dir=out_dir)
52
- os.close(fd)
53
 
54
- # Download the processed studio-quality audio
55
  audio_data = requests.get(result.audio.url).content
56
- with open(final_audio_path, "wb") as f:
 
 
 
57
  f.write(audio_data)
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  return {
60
- 'audio_path': final_audio_path,
61
  'stats': {
62
- 'noise_method': "Cleanvoice API (Studio Sound)",
63
  'processing_sec': 0,
64
  'fillers_removed': "Cleanvoice",
65
  'stutters_removed': "Cleanvoice"
66
  }
67
  }
68
 
69
- # We keep this dummy method so your UI doesn't crash!
70
- # Cleanvoice cuts the audio, but we still need to clean the text transcript.
71
  def clean_transcript_fillers(self, transcript: str) -> str:
72
  FILLER_WORDS = {
73
  "um", "umm", "uh", "hmm", "like", "basically", "literally",
@@ -80,12 +90,12 @@ class Denoiser:
80
  if clean_word not in FILLER_WORDS:
81
  result.append(w)
82
  return " ".join(result)
83
- # ══════════════════════════════════════════════════════════════════
 
84
  # DUMMY METHODS (To prevent app.py runtime crashes)
85
- # Cleanvoice already cut these in the cloud, so we just return the audio as-is.
86
  # ══════════════════════════════════════════════════════════════════
87
  def _remove_fillers(self, audio, sr, segments):
88
  return audio, 0
89
 
90
  def _remove_stutters(self, audio, sr, segments):
91
- return audio, 0
 
1
  """
2
  Department 1 β€” Cloud Denoiser (Cleanvoice API)
3
+ The "Vacuum-Sealed" Podcast Sound (MP3 Output)
4
  """
5
  import os
6
  import requests
7
  import tempfile
8
  import logging
9
  import re
10
+ import subprocess
11
 
12
  logger = logging.getLogger(__name__)
13
 
14
  class Denoiser:
15
  def __init__(self):
16
+ # ⚠️ API KEY LOADED
17
  self.api_key = "cvk_Xnmz7ZPXMRg.CcE3YGry3IzkCBWQKGvomBfd9hmC9L-aAvSj-2iNfyw"
18
  print("[Denoiser] ☁️ Cleanvoice Cloud API loaded")
19
 
 
28
  from cleanvoice import Cleanvoice
29
  except ImportError:
30
  raise RuntimeError("Please add cleanvoice-sdk to your requirements.txt")
 
 
 
31
 
32
  cv = Cleanvoice({'api_key': self.api_key})
33
 
 
44
  breath=remove_breaths
45
  )
46
 
47
+ logger.info(f"[Denoiser] Cloud processing complete. Downloading and converting to MP3...")
 
 
 
48
 
49
+ # 1. Download the raw audio from Cleanvoice
50
  audio_data = requests.get(result.audio.url).content
51
+
52
+ fd, temp_dl_path = tempfile.mkstemp(suffix=".tmp", dir=out_dir)
53
+ os.close(fd)
54
+ with open(temp_dl_path, "wb") as f:
55
  f.write(audio_data)
56
 
57
+ # 2. Convert directly to high-quality MP3 using ffmpeg
58
+ final_mp3_path = os.path.join(out_dir, "cleanvoice_studio.mp3")
59
+ subprocess.run([
60
+ "ffmpeg", "-y", "-i", temp_dl_path,
61
+ "-codec:a", "libmp3lame", "-qscale:a", "2",
62
+ final_mp3_path
63
+ ], capture_output=True)
64
+
65
+ # 3. Clean up the temporary download
66
+ try:
67
+ os.remove(temp_dl_path)
68
+ except OSError:
69
+ pass
70
+
71
  return {
72
+ 'audio_path': final_mp3_path,
73
  'stats': {
74
+ 'noise_method': "Cleanvoice API (Studio MP3)",
75
  'processing_sec': 0,
76
  'fillers_removed': "Cleanvoice",
77
  'stutters_removed': "Cleanvoice"
78
  }
79
  }
80
 
 
 
81
  def clean_transcript_fillers(self, transcript: str) -> str:
82
  FILLER_WORDS = {
83
  "um", "umm", "uh", "hmm", "like", "basically", "literally",
 
90
  if clean_word not in FILLER_WORDS:
91
  result.append(w)
92
  return " ".join(result)
93
+
94
+ # ══════════════════════════════════════════════════════════════════
95
  # DUMMY METHODS (To prevent app.py runtime crashes)
 
96
  # ══════════════════════════════════════════════════════════════════
97
  def _remove_fillers(self, audio, sr, segments):
98
  return audio, 0
99
 
100
  def _remove_stutters(self, audio, sr, segments):
101
+ return audio, 0