Spaces:
Runtime error
Runtime error
Commit
·
96cfbdb
1
Parent(s):
c5c3fcc
Add VoiceRSS TTS
Browse files- apps/mic.py +8 -21
- apps/utils.py +23 -0
apps/mic.py
CHANGED
|
@@ -4,7 +4,6 @@ import streamlit as st
|
|
| 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
|
|
@@ -12,7 +11,8 @@ from .utils import (
|
|
| 12 |
read_markdown,
|
| 13 |
tokenizer,
|
| 14 |
language_mapping,
|
| 15 |
-
code_to_name
|
|
|
|
| 16 |
)
|
| 17 |
import requests
|
| 18 |
from PIL import Image
|
|
@@ -24,10 +24,6 @@ from streamlit import caching
|
|
| 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,21 +137,12 @@ def app(state):
|
|
| 141 |
"**English Translation**: "+ sequence[0] if lang_id=="en" else translate(sequence[0])
|
| 142 |
)
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 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 |
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import pandas as pd
|
| 6 |
import os
|
|
|
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
import re
|
| 9 |
from mtranslate import translate
|
|
|
|
| 11 |
read_markdown,
|
| 12 |
tokenizer,
|
| 13 |
language_mapping,
|
| 14 |
+
code_to_name,
|
| 15 |
+
voicerss_tts
|
| 16 |
)
|
| 17 |
import requests
|
| 18 |
from PIL import Image
|
|
|
|
| 24 |
|
| 25 |
def app(state):
|
| 26 |
mic_state = state
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
with st.beta_expander("Usage"):
|
| 28 |
st.write(read_markdown("usage.md"))
|
| 29 |
st.write("\n")
|
|
|
|
| 137 |
"**English Translation**: "+ sequence[0] if lang_id=="en" else translate(sequence[0])
|
| 138 |
)
|
| 139 |
|
| 140 |
+
try:
|
| 141 |
+
clean_text = re.sub(r'[^A-Za-z0-9 ]+', '', sequence[0])
|
| 142 |
+
audio_bytes = voicerss_tts(clean_text, lang_id)
|
| 143 |
+
st.audio(audio_bytes, format='audio/mp3')
|
| 144 |
+
except:
|
| 145 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
|
| 148 |
|
apps/utils.py
CHANGED
|
@@ -5,9 +5,32 @@ from torchvision.transforms import CenterCrop, ConvertImageDtype, Normalize, Res
|
|
| 5 |
from torchvision.transforms.functional import InterpolationMode
|
| 6 |
from PIL import Image
|
| 7 |
import os
|
|
|
|
| 8 |
import streamlit as st
|
| 9 |
from transformers import MBart50TokenizerFast
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
class Toc:
|
| 12 |
def __init__(self):
|
| 13 |
self._items = []
|
|
|
|
| 5 |
from torchvision.transforms.functional import InterpolationMode
|
| 6 |
from PIL import Image
|
| 7 |
import os
|
| 8 |
+
import requests
|
| 9 |
import streamlit as st
|
| 10 |
from transformers import MBart50TokenizerFast
|
| 11 |
|
| 12 |
+
|
| 13 |
+
def voicerss_tts(text, lang_id):
|
| 14 |
+
lang_id_to_code_map = {
|
| 15 |
+
"en": "en-us",
|
| 16 |
+
"fr": "fr-fr",
|
| 17 |
+
"de": "de-de",
|
| 18 |
+
"es": "es-es"
|
| 19 |
+
|
| 20 |
+
}
|
| 21 |
+
url = "https://voicerss-text-to-speech.p.rapidapi.com/"
|
| 22 |
+
|
| 23 |
+
querystring = {"key":"undefined","hl":lang_id_to_code_map[lang_id],"src":text,"f":"8khz_8bit_mono","c":"mp3","r":"0"}
|
| 24 |
+
|
| 25 |
+
headers = {
|
| 26 |
+
'x-rapidapi-key': st.secrets["voicerss_key"],
|
| 27 |
+
'x-rapidapi-host': "voicerss-text-to-speech.p.rapidapi.com"
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
response = requests.request("GET", url, headers=headers, params=querystring)
|
| 31 |
+
|
| 32 |
+
return response.content
|
| 33 |
+
|
| 34 |
class Toc:
|
| 35 |
def __init__(self):
|
| 36 |
self._items = []
|