Spaces:
Sleeping
Sleeping
Devin Xie
commited on
Commit
·
ba596b5
1
Parent(s):
5ed26b8
changed model function call
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import torch
|
|
| 2 |
import os
|
| 3 |
import streamlit as st
|
| 4 |
from TTS.api import TTS
|
|
|
|
| 5 |
|
| 6 |
# By using XTTS you agree to CPML license https://coqui.ai/cpml
|
| 7 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
|
@@ -12,7 +13,11 @@ def generate_audio(audio_file, text_input):
|
|
| 12 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 13 |
tts = TTS(model).to(device)
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def main():
|
| 18 |
# Title
|
|
@@ -29,18 +34,21 @@ def main():
|
|
| 29 |
# Input text
|
| 30 |
text_input = st.text_input('Enter the text to synthesize')
|
| 31 |
|
| 32 |
-
if uploaded_file is not None
|
| 33 |
-
if
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
if __name__ == '__main__':
|
| 46 |
main()
|
|
|
|
| 2 |
import os
|
| 3 |
import streamlit as st
|
| 4 |
from TTS.api import TTS
|
| 5 |
+
from tempfile import NamedTemporaryFile
|
| 6 |
|
| 7 |
# By using XTTS you agree to CPML license https://coqui.ai/cpml
|
| 8 |
os.environ["COQUI_TOS_AGREED"] = "1"
|
|
|
|
| 13 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 14 |
tts = TTS(model).to(device)
|
| 15 |
|
| 16 |
+
with NamedTemporaryFile(delete=False, suffix='.wav') as tmp_file:
|
| 17 |
+
output_path = tmp_file.name
|
| 18 |
+
tts.tts_to_file(text=text_input, speaker_wav=audio_file, language='en', file_path=output_path)
|
| 19 |
+
|
| 20 |
+
return output_path
|
| 21 |
|
| 22 |
def main():
|
| 23 |
# Title
|
|
|
|
| 34 |
# Input text
|
| 35 |
text_input = st.text_input('Enter the text to synthesize')
|
| 36 |
|
| 37 |
+
if uploaded_file is not None:
|
| 38 |
+
if text_input:
|
| 39 |
+
if st.button('Synthesize'):
|
| 40 |
+
with st.spinner('Synthesizing...'):
|
| 41 |
+
output_path = generate_audio(uploaded_file, text_input)
|
| 42 |
+
|
| 43 |
+
col1, col2 = st.columns(2)
|
| 44 |
+
with col1:
|
| 45 |
+
st.header('Reference Audio')
|
| 46 |
+
st.audio(uploaded_file, format='audio/wav')
|
| 47 |
+
with col2:
|
| 48 |
+
st.header('Synthesized Audio')
|
| 49 |
+
st.audio(output_path, format='audio/wav')
|
| 50 |
+
else:
|
| 51 |
+
st.error('Please provide a text input!')
|
| 52 |
|
| 53 |
if __name__ == '__main__':
|
| 54 |
main()
|