Spaces:
Running
Running
Devin Xie
commited on
Commit
·
60a8de0
1
Parent(s):
23b908d
improved code format
Browse files
app.py
CHANGED
@@ -6,10 +6,13 @@ from TTS.api import TTS
|
|
6 |
# By using XTTS you agree to CPML license https://coqui.ai/cpml
|
7 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
def main():
|
15 |
# Title
|
@@ -17,7 +20,7 @@ def main():
|
|
17 |
st.markdown(title, unsafe_allow_html=True)
|
18 |
|
19 |
# Subtitle
|
20 |
-
title = f"""<h2 align="center" style="font-size: 1.
|
21 |
st.markdown(title, unsafe_allow_html=True)
|
22 |
|
23 |
# Upload audio file
|
@@ -27,11 +30,18 @@ def main():
|
|
27 |
# Input text
|
28 |
text_input = st.text_input('Enter the text to synthesize')
|
29 |
|
30 |
-
if
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
if __name__ == '__main__':
|
37 |
main()
|
|
|
6 |
# By using XTTS you agree to CPML license https://coqui.ai/cpml
|
7 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
8 |
|
9 |
+
def generate_audio(audio_file, text_input):
|
10 |
+
# Initialize model
|
11 |
+
model = "tts_models/multilingual/multi-dataset/xtts_v2"
|
12 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
13 |
+
tts = TTS(model).to(device)
|
14 |
+
|
15 |
+
tts.tts_to_file(text=text_input, speaker_wav=audio_file, language='en')
|
16 |
|
17 |
def main():
|
18 |
# Title
|
|
|
20 |
st.markdown(title, unsafe_allow_html=True)
|
21 |
|
22 |
# Subtitle
|
23 |
+
title = f"""<h2 align="center" style="font-size: 1.2rem; margin-bottom: 2rem;">Make your favorite characters say anything!</h2>"""
|
24 |
st.markdown(title, unsafe_allow_html=True)
|
25 |
|
26 |
# Upload audio file
|
|
|
30 |
# Input text
|
31 |
text_input = st.text_input('Enter the text to synthesize')
|
32 |
|
33 |
+
if uploaded_file is not None and text_input is not "":
|
34 |
+
if st.button('Synthesize'):
|
35 |
+
with st.spinner('Synthesizing...'):
|
36 |
+
output_audio = generate_audio(uploaded_file, text_input)
|
37 |
+
|
38 |
+
col1, col2 = st.columns(2)
|
39 |
+
with col1:
|
40 |
+
st.header('Reference Audio')
|
41 |
+
st.audio(uploaded_file, format='audio/wav')
|
42 |
+
with col2:
|
43 |
+
st.header('Synthesized Audio')
|
44 |
+
st.audio(output_audio, format='audio/wav')
|
45 |
|
46 |
if __name__ == '__main__':
|
47 |
main()
|