-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
executable file
·134 lines (100 loc) · 4.37 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from time import time
import streamlit as st
import subprocess
import io
# Function to inject custom CSS
def local_css(file_name):
with open(file_name) as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
st.set_page_config(
page_title='DataCula perTTS',
page_icon=':rocket:'
)
# Sidebar
st.sidebar.image('./img/datacula.png', width=32)
st.sidebar.markdown(
"Let's explore data science with [DataCula!](https://datacula.com)"
)
st.sidebar.header("Voice")
st.sidebar.markdown(
"We are using an AI based TTS system ;)"
)
st.sidebar.header("Repository")
st.sidebar.markdown(
"pertts-streamlit @ [github](https://github.com/SadeghKrmi/pertts-streamlit.git)"
)
st.sidebar.header("Contact")
st.sidebar.markdown(
)
st.title(":speech_balloon: Persian AI text-to-speech")
"""
We're very excited to release `DataCula perTTS`, which coverts text to speech in persian/farsi using piper.
"""
tab1, tab2, tab3 = st.tabs([
":loudspeaker: Convert text",
":keyboard: Check a word",
":information_source: Information",
])
# Injecting the CSS
local_css("style.css")
with tab1:
# txt = st.text_area("Let us convert your text, we try not to disappoint you ;)","لطفا متن خود را وارد نمایید")
txt = st.text_area("Let us convert your text, we try not to disappoint you ;)","علت اصلیِ بارشِ باران جابجایی هوای مرطوب به علت اختلاف دما و رطوبت است که به جبهههای هواشناسی معروف است.")
col1, col2 = st.columns(2)
with col2:
modelname = st.selectbox(
'Please select the model to generate audio.',
(
'ganji',
'amir',
),
label_visibility = "collapsed",
)
models = {
'ganji': 'ganji/epoch=5719-step=2609600-ganji.onnx',
'amir': 'amir/epoch=5261-step=2455712.onnx'
}
model = models.get(modelname)
with col1:
if st.button('generate'):
epoch = time()
wav_filename = str(epoch).replace('.', '') + ".wav"
wav_filepath = "./audio-out/" + wav_filename
gCommand = ['bash', '-c', 'echo "{txt}" | /root/piper/build/piper --data-dir /usr/share/espeak-ng-data --model ./model/{model} --output_file {wav_filepath} --sentence_silence 0.3'.format(txt=txt, model=model,wav_filepath=wav_filepath)]
with st.spinner('Wait for it...'):
try:
process = subprocess.run(gCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
audio_file = open(wav_filepath, 'rb')
audio_bytes = audio_file.read()
st.audio(audio_bytes, format='audio/wav')
rCommand = ['bash', '-c', 'rm -rf {wav_filepath}'.format(wav_filepath=wav_filepath) ]
process = subprocess.run(rCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Error executing the command for audio geneation: {e}")
rCommand = ['bash', '-c', 'rm -rf {wav_filepath}'.format(wav_filepath=wav_filepath) ]
process = subprocess.run(rCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
st.write("Error generating the audio, please contact us at [email protected]")
with tab2:
word = st.text_input('Check word(s) spelling in phoneme format', 'نمایش واج آرایی کلمه ها')
if st.button('check'):
command = [
"/usr/bin/espeak-ng",
"-v", "fa",
"-q", "--ipa",
word
]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode == 0:
stdout = stdout.decode('utf-8')
st.write(word, '\u2194', stdout)
with tab3:
"""
Please use the diacritics to generate moe sensible pronounciations. \n
shift+d --> کسره \n
shift+s --> ضمه \n
shift+a --> فتح \n
shift+f --> تشدید \n
"""