Spaces:
Sleeping
Sleeping
Upload convert_audio.py
Browse files- src/modules/convert_audio.py +22 -0
src/modules/convert_audio.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Convert audio to other formats"""
|
| 2 |
+
|
| 3 |
+
from pydub import AudioSegment
|
| 4 |
+
import librosa
|
| 5 |
+
import soundfile as sf
|
| 6 |
+
|
| 7 |
+
from modules.console_colors import ULTRASINGER_HEAD
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def convert_audio_to_mono_wav(input_file_path: str, output_file_path: str) -> None:
|
| 11 |
+
"""Convert audio to mono wav"""
|
| 12 |
+
print(f"{ULTRASINGER_HEAD} Converting audio for AI")
|
| 13 |
+
y, sr = librosa.load(input_file_path, mono=True, sr=None)
|
| 14 |
+
sf.write(output_file_path, y, sr)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def convert_wav_to_mp3(input_file_path: str, output_file_path: str) -> None:
|
| 18 |
+
"""Convert wav to mp3"""
|
| 19 |
+
print(f"{ULTRASINGER_HEAD} Converting wav to mp3")
|
| 20 |
+
|
| 21 |
+
sound = AudioSegment.from_wav(input_file_path)
|
| 22 |
+
sound.export(output_file_path, format="mp3")
|