Spaces:
Runtime error
Runtime error
antoniomae
commited on
Commit
•
e19420d
1
Parent(s):
6ba63e8
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from TTS.api import TTS
|
2 |
+
from bs4 import BeautifulSoup
|
3 |
+
import requests
|
4 |
+
import streamlit as st
|
5 |
+
import tempfile
|
6 |
+
import os
|
7 |
+
import json
|
8 |
+
import datetime
|
9 |
+
|
10 |
+
with open('config.json', 'r') as f:
|
11 |
+
config = json.load(f)
|
12 |
+
|
13 |
+
APP_NAME = config['APP_NAME']
|
14 |
+
APP_LOGO = config['APP_LOGO']
|
15 |
+
APP_DESCRIPTION = config['APP_DESCRIPTION']
|
16 |
+
|
17 |
+
def contains_only_ascii(input_string):
|
18 |
+
return all(ord(char) < 128 for char in input_string)
|
19 |
+
|
20 |
+
def create_temp_file(input_wav):
|
21 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
22 |
+
temp_file.write(input_wav.read())
|
23 |
+
return temp_file
|
24 |
+
|
25 |
+
def remove_temp_file(temp_file):
|
26 |
+
temp_file.close()
|
27 |
+
os.remove(temp_file.name)
|
28 |
+
|
29 |
+
def update_progress(percent, text):
|
30 |
+
progress_bar.progress(percent)
|
31 |
+
status_text.text(text)
|
32 |
+
|
33 |
+
st.set_page_config(page_title=APP_NAME)
|
34 |
+
st.title(APP_NAME)
|
35 |
+
st.image(APP_LOGO, use_column_width=True)
|
36 |
+
st.markdown(APP_DESCRIPTION)
|
37 |
+
|
38 |
+
input_wav = st.file_uploader("Upload a WAV file with your voice", type=["wav"])
|
39 |
+
clone_wav = st.file_uploader("Upload a WAV file with voice to clone", type=["wav"])
|
40 |
+
|
41 |
+
if input_wav and clone_wav:
|
42 |
+
progress_bar = st.progress(0)
|
43 |
+
status_text = st.empty()
|
44 |
+
|
45 |
+
current_datetime = datetime.datetime.now()
|
46 |
+
formatted_datetime = current_datetime.strftime("%Y-%m-%d_%H%M%S")
|
47 |
+
output_filename = f"recording_{formatted_datetime}.wav"
|
48 |
+
|
49 |
+
temp_input_file = create_temp_file(input_wav)
|
50 |
+
temp_clone_file = create_temp_file(clone_wav)
|
51 |
+
|
52 |
+
update_progress(0, 'Loading TTS model...')
|
53 |
+
api = TTS("voice_conversion_models/multilingual/vctk/freevc24")
|
54 |
+
|
55 |
+
update_progress(50, 'Generating audio...')
|
56 |
+
api.voice_conversion_to_file(
|
57 |
+
source_wav=temp_input_file.name,
|
58 |
+
target_wav=temp_clone_file.name,
|
59 |
+
file_path=output_filename
|
60 |
+
)
|
61 |
+
|
62 |
+
remove_temp_file(temp_input_file)
|
63 |
+
remove_temp_file(temp_clone_file)
|
64 |
+
|
65 |
+
audio_file = open(output_filename, 'rb')
|
66 |
+
audio_bytes = audio_file.read()
|
67 |
+
|
68 |
+
update_progress(100, 'Audio generated successfully!')
|
69 |
+
|
70 |
+
st.audio(audio_bytes, format='audio/wav')
|
71 |
+
|
72 |
+
st.download_button('Download WAV', data=audio_bytes, file_name='output.wav')
|