Spaces:
Paused
Paused
Amamrnaf
commited on
Commit
·
46a25e1
1
Parent(s):
67743da
new file
Browse files- coqui_tts.py +32 -0
coqui_tts.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import noisereduce as nr
|
3 |
+
import soundfile as sf
|
4 |
+
from moviepy.editor import *
|
5 |
+
import string
|
6 |
+
import json
|
7 |
+
from glob import glob
|
8 |
+
import torchaudio
|
9 |
+
import subprocess
|
10 |
+
import shutil
|
11 |
+
import pyloudnorm as pyln
|
12 |
+
import torch
|
13 |
+
from TTS.api import TTS
|
14 |
+
|
15 |
+
|
16 |
+
def run_audio_generation_v1(text,accent='None'):
|
17 |
+
gpu = True if torch.cuda.is_available() else False
|
18 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=gpu) # gpu should be true when server (cuda)
|
19 |
+
|
20 |
+
# pre-process story audio file
|
21 |
+
# convert to 16 bit mono
|
22 |
+
# remove noise
|
23 |
+
speaker_wav_data, speaker_wav_rate = sf.read("./tmp/audio/input_src/0.wav")
|
24 |
+
speaker_wav_data_no_noise = nr.reduce_noise(y=speaker_wav_data, sr=speaker_wav_rate)
|
25 |
+
sf.write('./tmp/audio/speaker_wav.wav', speaker_wav_data_no_noise, speaker_wav_rate, subtype='PCM_16')
|
26 |
+
|
27 |
+
tts.tts_to_file(
|
28 |
+
text,
|
29 |
+
speaker_wav="./tmp/audio/speaker_wav.wav",
|
30 |
+
language="en",
|
31 |
+
file_path="audio/output.wav"
|
32 |
+
)
|