Brasd99 commited on
Commit
f2a547a
1 Parent(s): d5d1416

Initial commit

Browse files
Files changed (3) hide show
  1. app.py +83 -0
  2. config.json +7 -0
  3. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
9
+ with open('config.json', 'r') as f:
10
+ config = json.load(f)
11
+
12
+ LANGUAGES_URL = config['LANGUAGES_URL']
13
+ OUTPUT_FILENAME = config['OUTPUT_FILENAME']
14
+
15
+ def get_iso_languages():
16
+ response = requests.get(LANGUAGES_URL)
17
+ soup = BeautifulSoup(response.text, 'html.parser')
18
+
19
+ p_tags = soup.find_all('p')
20
+
21
+ iso_language_dict = {}
22
+
23
+ for p_tag in p_tags[1:]: # Skipping the first <p> which contains the header
24
+ parts = p_tag.get_text().split()
25
+ if len(parts) == 2:
26
+ iso_code, language_name = parts
27
+ iso_language_dict[language_name] = iso_code
28
+
29
+ return iso_language_dict
30
+
31
+ def create_temp_file(input_wav):
32
+ temp_file = tempfile.NamedTemporaryFile(delete=False)
33
+ temp_file.write(input_wav.read())
34
+ return temp_file
35
+
36
+ def remove_temp_file(temp_file):
37
+ temp_file.close()
38
+ os.remove(temp_file.name)
39
+
40
+ def update_progress(percent, text):
41
+ progress_bar.progress(percent)
42
+ status_text.text(text)
43
+
44
+ iso_languages = get_iso_languages()
45
+ languages = list(iso_languages.keys())
46
+
47
+ language = st.selectbox('Select a language', languages)
48
+ text = st.text_input('Enter some text')
49
+ input_wav = st.file_uploader("Upload a WAV file", type=["wav"])
50
+
51
+ if input_wav:
52
+ if not input_wav or input_wav is None:
53
+ st.error('Please upload wav input audio')
54
+ elif not text:
55
+ st.error('Please write text')
56
+ else:
57
+ progress_bar = st.progress(0)
58
+ status_text = st.empty()
59
+
60
+ temp_file = create_temp_file(input_wav)
61
+
62
+ iso_code = iso_languages[language]
63
+
64
+ update_progress(0, 'Loading TTS model...')
65
+ api = TTS(f"tts_models/{iso_code}/fairseq/vits")
66
+
67
+ update_progress(50, 'Generating audio...')
68
+ api.tts_with_vc_to_file(
69
+ text,
70
+ speaker_wav=temp_file.name,
71
+ file_path=OUTPUT_FILENAME
72
+ )
73
+
74
+ remove_temp_file(temp_file)
75
+
76
+ audio_file = open(OUTPUT_FILENAME, 'rb')
77
+ audio_bytes = audio_file.read()
78
+
79
+ update_progress(100, 'Audio generated successfully!')
80
+
81
+ st.audio(audio_bytes, format='audio/wav')
82
+
83
+ st.download_button('Download WAV', data=audio_bytes, file_name='file.wav')
config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "APP_NAME": "TTS-Voice-Cloner",
3
+ "APP_LOGO": "",
4
+ "APP_DESCRIPTION": "The service allows you to clone a voice from a given audio recording and produce text voice acting",
5
+ "LANGUAGES_URL": "https://dl.fbaipublicfiles.com/mms/tts/all-tts-languages.html",
6
+ "OUTPUT_FILENAME": "output.wav"
7
+ }
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ beautifulsoup4
2
+ TTS