Spaces:
Runtime error
Runtime error
gchhablani
commited on
Commit
·
d74f133
1
Parent(s):
e6c6e8b
Add TTS to demo
Browse files- apps/mic.py +21 -0
- requirements.txt +2 -1
apps/mic.py
CHANGED
@@ -4,7 +4,9 @@ import streamlit as st
|
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
6 |
import os
|
|
|
7 |
import matplotlib.pyplot as plt
|
|
|
8 |
from mtranslate import translate
|
9 |
from .utils import (
|
10 |
read_markdown,
|
@@ -22,6 +24,10 @@ from streamlit import caching
|
|
22 |
|
23 |
def app(state):
|
24 |
mic_state = state
|
|
|
|
|
|
|
|
|
25 |
with st.beta_expander("Usage"):
|
26 |
st.write(read_markdown("usage.md"))
|
27 |
st.write("\n")
|
@@ -135,6 +141,21 @@ def app(state):
|
|
135 |
"**English Translation**: "+ sequence[0] if lang_id=="en" else translate(sequence[0])
|
136 |
)
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
|
140 |
|
|
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
6 |
import os
|
7 |
+
import pyttsx3
|
8 |
import matplotlib.pyplot as plt
|
9 |
+
import re
|
10 |
from mtranslate import translate
|
11 |
from .utils import (
|
12 |
read_markdown,
|
|
|
24 |
|
25 |
def app(state):
|
26 |
mic_state = state
|
27 |
+
engine = pyttsx3.init()
|
28 |
+
engine.setProperty('rate', 100)
|
29 |
+
voices = engine.getProperty('voices')
|
30 |
+
engine.setProperty('voice', voices[1].id)
|
31 |
with st.beta_expander("Usage"):
|
32 |
st.write(read_markdown("usage.md"))
|
33 |
st.write("\n")
|
|
|
141 |
"**English Translation**: "+ sequence[0] if lang_id=="en" else translate(sequence[0])
|
142 |
)
|
143 |
|
144 |
+
try:
|
145 |
+
clean_text = re.sub(r'[^A-Za-z0-9 ]+', '', sequence[0])
|
146 |
+
engine.say(clean_text)
|
147 |
+
engine.runAndWait()
|
148 |
+
engine.stop()
|
149 |
+
|
150 |
+
engine.save_to_file(clean_text, 'temp.mp3')
|
151 |
+
engine.runAndWait()
|
152 |
+
|
153 |
+
|
154 |
+
audio_file = open('temp.mp3', 'rb')
|
155 |
+
audio_bytes = audio_file.read()
|
156 |
+
st.audio(audio_bytes, format='audio/mp3')
|
157 |
+
except:
|
158 |
+
pass
|
159 |
|
160 |
|
161 |
|
requirements.txt
CHANGED
@@ -5,4 +5,5 @@ torchvision==0.10.0
|
|
5 |
mtranslate==1.8
|
6 |
black==21.7b0
|
7 |
flax==0.3.4
|
8 |
-
sentencepiece==0.1.96
|
|
|
|
5 |
mtranslate==1.8
|
6 |
black==21.7b0
|
7 |
flax==0.3.4
|
8 |
+
sentencepiece==0.1.96
|
9 |
+
pyttsx3==2.90
|