Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import shutil
|
|
| 5 |
#from huggingface_hub import snapshot_download
|
| 6 |
import numpy as np
|
| 7 |
from scipy.io import wavfile
|
|
|
|
| 8 |
"""
|
| 9 |
model_ids = [
|
| 10 |
'suno/bark',
|
|
@@ -25,12 +26,40 @@ model.load_checkpoint(config, checkpoint_dir="checkpoints/bark", eval=True)
|
|
| 25 |
from TTS.api import TTS
|
| 26 |
tts = TTS("tts_models/multilingual/multi-dataset/bark", gpu=True)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
def infer(prompt, input_wav_file):
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
print("SAVING THE AUDIO FILE TO WHERE IT BELONGS")
|
| 31 |
|
| 32 |
# Path to your WAV file
|
| 33 |
-
source_path =
|
| 34 |
|
| 35 |
# Destination directory
|
| 36 |
destination_directory = "bark_voices"
|
|
|
|
| 5 |
#from huggingface_hub import snapshot_download
|
| 6 |
import numpy as np
|
| 7 |
from scipy.io import wavfile
|
| 8 |
+
from pydub import AudioSegment
|
| 9 |
"""
|
| 10 |
model_ids = [
|
| 11 |
'suno/bark',
|
|
|
|
| 26 |
from TTS.api import TTS
|
| 27 |
tts = TTS("tts_models/multilingual/multi-dataset/bark", gpu=True)
|
| 28 |
|
| 29 |
+
def cut_wav(input_path, max_duration):
|
| 30 |
+
# Load the WAV file
|
| 31 |
+
audio = AudioSegment.from_wav(input_path)
|
| 32 |
+
|
| 33 |
+
# Calculate the duration of the audio
|
| 34 |
+
audio_duration = len(audio) / 1000 # Convert milliseconds to seconds
|
| 35 |
+
|
| 36 |
+
# Determine the duration to cut (maximum of max_duration and actual audio duration)
|
| 37 |
+
cut_duration = min(max_duration, audio_duration)
|
| 38 |
+
|
| 39 |
+
# Cut the audio
|
| 40 |
+
cut_audio = audio[:int(cut_duration * 1000)] # Convert seconds to milliseconds
|
| 41 |
+
|
| 42 |
+
# Get the input file name without extension
|
| 43 |
+
file_name = os.path.splitext(os.path.basename(input_path))[0]
|
| 44 |
+
|
| 45 |
+
# Construct the output file path with the original file name and "_cut" suffix
|
| 46 |
+
output_path = f"{file_name}_cut.wav"
|
| 47 |
+
|
| 48 |
+
# Save the cut audio as a new WAV file
|
| 49 |
+
cut_audio.export(output_path, format="wav")
|
| 50 |
+
|
| 51 |
+
return output_path
|
| 52 |
+
|
| 53 |
def infer(prompt, input_wav_file):
|
| 54 |
|
| 55 |
+
print("CUT AUDIO FILE TO MAX 20 SECONDS")
|
| 56 |
+
|
| 57 |
+
cut_input_wav_file = cut_wav(input_wav_file, max_duration=20)
|
| 58 |
+
|
| 59 |
print("SAVING THE AUDIO FILE TO WHERE IT BELONGS")
|
| 60 |
|
| 61 |
# Path to your WAV file
|
| 62 |
+
source_path = cut_input_wav_file
|
| 63 |
|
| 64 |
# Destination directory
|
| 65 |
destination_directory = "bark_voices"
|