Spaces:
Sleeping
Sleeping
Update src/audio_preprocessing.py
Browse files
src/audio_preprocessing.py
CHANGED
|
@@ -162,13 +162,13 @@ def denoise_audio(input_audio_path):
|
|
| 162 |
audio = audio.set_channels(1) # Convert to mono
|
| 163 |
audio = audio.set_sample_width(2) # Set to 16-bit
|
| 164 |
|
| 165 |
-
# Export as
|
| 166 |
-
|
| 167 |
-
audio.export(
|
| 168 |
|
| 169 |
-
# Run denoising
|
| 170 |
result = subprocess.run(
|
| 171 |
-
["denoise",
|
| 172 |
check=True,
|
| 173 |
capture_output=True,
|
| 174 |
text=True
|
|
@@ -176,7 +176,7 @@ def denoise_audio(input_audio_path):
|
|
| 176 |
print(result.stdout)
|
| 177 |
|
| 178 |
# Clean up
|
| 179 |
-
os.remove(
|
| 180 |
|
| 181 |
except subprocess.CalledProcessError as e:
|
| 182 |
print(f"Error: {e}")
|
|
|
|
| 162 |
audio = audio.set_channels(1) # Convert to mono
|
| 163 |
audio = audio.set_sample_width(2) # Set to 16-bit
|
| 164 |
|
| 165 |
+
# Export as WAV with correct format
|
| 166 |
+
temp_wav = "temp_audio.wav"
|
| 167 |
+
audio.export(temp_wav, format="wav")
|
| 168 |
|
| 169 |
+
# Run denoising
|
| 170 |
result = subprocess.run(
|
| 171 |
+
["denoise", temp_wav, output_audio_path, "--plot"],
|
| 172 |
check=True,
|
| 173 |
capture_output=True,
|
| 174 |
text=True
|
|
|
|
| 176 |
print(result.stdout)
|
| 177 |
|
| 178 |
# Clean up
|
| 179 |
+
os.remove(temp_wav)
|
| 180 |
|
| 181 |
except subprocess.CalledProcessError as e:
|
| 182 |
print(f"Error: {e}")
|