Spaces:
Runtime error
Runtime error
Add the tts feature into app
Browse files
app.py
CHANGED
|
@@ -8,9 +8,23 @@ import json
|
|
| 8 |
import os
|
| 9 |
import random
|
| 10 |
import openai
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
openai.api_key = os.getenv("OPENAI_KEY")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
@st.cache_resource
|
| 16 |
def load_model():
|
|
@@ -141,9 +155,14 @@ def mispronounciation_detection_section():
|
|
| 141 |
|
| 142 |
st.divider()
|
| 143 |
|
| 144 |
-
# display more prompts to practice -- 1 from ChatGPT -- based on user's mistakes, 2 from L2 Arctic
|
| 145 |
st.write('#### What is next?')
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
st.write('Here are some more prompts for you to practice:')
|
| 148 |
|
| 149 |
selected_prompts = []
|
|
|
|
| 8 |
import os
|
| 9 |
import random
|
| 10 |
import openai
|
| 11 |
+
from gtts import gTTS
|
| 12 |
+
from io import BytesIO
|
| 13 |
|
| 14 |
openai.api_key = os.getenv("OPENAI_KEY")
|
| 15 |
+
# https://gtts.readthedocs.io/en/latest/
|
| 16 |
+
#
|
| 17 |
+
def tts_gtts(text):
|
| 18 |
+
mp3_fp = BytesIO()
|
| 19 |
+
tts = gTTS(text, lang="en")
|
| 20 |
+
tts.write_to_fp(mp3_fp)
|
| 21 |
+
return mp3_fp
|
| 22 |
+
|
| 23 |
+
def pronounce(text):
|
| 24 |
+
if len(text) > 0:
|
| 25 |
+
data = tts_gtts(text)
|
| 26 |
+
return data
|
| 27 |
+
return []
|
| 28 |
|
| 29 |
@st.cache_resource
|
| 30 |
def load_model():
|
|
|
|
| 155 |
|
| 156 |
st.divider()
|
| 157 |
|
|
|
|
| 158 |
st.write('#### What is next?')
|
| 159 |
|
| 160 |
+
# display pronounciation e.g.
|
| 161 |
+
st.write("Here is a pronounced sample")
|
| 162 |
+
pronounced_sample = pronounce(text)
|
| 163 |
+
st.audio(pronounced_sample, format="audio/wav", start_time=0)
|
| 164 |
+
|
| 165 |
+
# display more prompts to practice -- 1 from ChatGPT -- based on user's mistakes, 2 from L2 Arctic
|
| 166 |
st.write('Here are some more prompts for you to practice:')
|
| 167 |
|
| 168 |
selected_prompts = []
|