Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import torch
|
|
5 |
import zipfile
|
6 |
from TTS.api import TTS
|
7 |
from pydub import AudioSegment
|
|
|
8 |
|
9 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
10 |
|
@@ -47,8 +48,15 @@ def convert_to_wav(input_audio_file):
|
|
47 |
return "temp.wav"
|
48 |
return input_audio_file
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
def synthesize_text(text, input_audio_file, language):
|
51 |
input_audio_file = convert_to_wav(input_audio_file)
|
|
|
52 |
tts.tts_to_file(text=text, speaker_wav=input_audio_file, language=language, file_path="./output.wav")
|
53 |
return "./output.wav"
|
54 |
|
@@ -73,15 +81,16 @@ def clone(text, input_file, language, url=None, use_url=False):
|
|
73 |
input_audio_file = input_file.name
|
74 |
|
75 |
output_file_path = synthesize_text(text, input_audio_file, language)
|
76 |
-
|
77 |
|
78 |
iface = gr.Interface(
|
79 |
fn=clone,
|
80 |
-
inputs=["text", gr.File(label="Input File", file_types=[".zip",
|
81 |
-
outputs=
|
82 |
-
title=
|
83 |
-
description="
|
84 |
-
theme=
|
|
|
85 |
)
|
86 |
|
87 |
-
iface.launch(
|
|
|
5 |
import zipfile
|
6 |
from TTS.api import TTS
|
7 |
from pydub import AudioSegment
|
8 |
+
import mecab
|
9 |
|
10 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
11 |
|
|
|
48 |
return "temp.wav"
|
49 |
return input_audio_file
|
50 |
|
51 |
+
def preprocess_text(txt, katsu):
|
52 |
+
if katsu:
|
53 |
+
tagger = mecab.Tagger()
|
54 |
+
txt = tagger.parse(txt).strip()
|
55 |
+
return txt
|
56 |
+
|
57 |
def synthesize_text(text, input_audio_file, language):
|
58 |
input_audio_file = convert_to_wav(input_audio_file)
|
59 |
+
text = preprocess_text(text, language == "ja")
|
60 |
tts.tts_to_file(text=text, speaker_wav=input_audio_file, language=language, file_path="./output.wav")
|
61 |
return "./output.wav"
|
62 |
|
|
|
81 |
input_audio_file = input_file.name
|
82 |
|
83 |
output_file_path = synthesize_text(text, input_audio_file, language)
|
84 |
+
returnoutput_file_path
|
85 |
|
86 |
iface = gr.Interface(
|
87 |
fn=clone,
|
88 |
+
inputs=["text", gr.File(label="Input File", file_types=[".zip", ".wav", ".mp3", ".flac", ".mp4"]), "language", "url", gr.Checkbox(label="Use URL")],
|
89 |
+
outputs="text",
|
90 |
+
title="Voice Cloning Application",
|
91 |
+
description="Enter text, select an audio file, choose a language, and optionally input a URL to clone a voice.",
|
92 |
+
theme="default",
|
93 |
+
allow_flagging="never"
|
94 |
)
|
95 |
|
96 |
+
iface.launch()
|