Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -38,9 +38,9 @@ data = {
|
|
38 |
"speaker_options": ["en","en-us","en-029","n-gb-x-gbclan","en-gb-x-rp","en-gb-scotland","en-gb-gbcwmd", "es", "de", "pl","ar","be","bn","bpy","bs","bg","ca","yue","hak","haw","cmn","hr","cs","da","nl","eo","et","fa","fa-latn","fi","fr-be","fr","ga","gd","ka","grc","el","kl","gn","gu","ht","he","hi","hu","id","io","it","ja","kn","kok","ko","ku","kk","ky","la","lb","ltg","lv","lfn","lt","jbo","mi","mk","ms","ml","mt","mr","nci","ne","nb","nog","or","om","pap","pt-br","pt","ro","ru","ru-lv","uk","sjn","sr","tn","sd","shn","si","sk","sl","es","es-419","sw","sv","ta","th","tk","tt","te","tr","ug","ur","uz","vi-vn-x-central","vi","vi0vn-x-south"],
|
39 |
"default_speaker": "en",
|
40 |
}
|
41 |
-
|
42 |
-
async def read_root(request: Request):
|
43 |
-
return templates.TemplateResponse("interface.html", {"request": request, "data": data})
|
44 |
|
45 |
import json
|
46 |
import logging
|
@@ -114,13 +114,13 @@ renamed_audio_file = None
|
|
114 |
#@app.post("/", response_class=FileResponse)
|
115 |
@app.post("/", response_class=HTMLResponse)
|
116 |
async def main(
|
117 |
-
request: Request,
|
118 |
text_input: str = Form(...),
|
119 |
speaker: str = Form(...),
|
120 |
speed_slider: float = Form(...),
|
121 |
noise_scale_slider: float = Form(...),
|
122 |
noise_scale_w_slider: float = Form(...),
|
123 |
-
play: bool = Form(True)
|
|
|
124 |
):
|
125 |
"""Main entry point"""
|
126 |
sys.path.append('./content/piper/src/python')
|
@@ -148,6 +148,13 @@ async def main(
|
|
148 |
playaudio("novoices")
|
149 |
raise Exception(lan.translate(lang, "No downloaded voice packages!"))
|
150 |
elif isinstance(onnx_models, str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
onnx_model = onnx_models
|
152 |
model, config = load_onnx(onnx_model, sess_options, providers)
|
153 |
config["espeak"]["voice"] = speaker
|
@@ -195,6 +202,13 @@ async def main(
|
|
195 |
|
196 |
# Create a URL to download the file
|
197 |
file_url = f'/download?fileId={file_id}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
# os.rename(temp_audio_file, renamed_audio_file)
|
199 |
|
200 |
# Specify the path to your MP3 audio file
|
@@ -255,7 +269,7 @@ async def main(
|
|
255 |
|
256 |
|
257 |
# Save the audio as a temporary WAV file
|
258 |
-
return templates.TemplateResponse("interface.html", {"request": request, "file_url": file_url, "data": data})
|
259 |
|
260 |
# Serve the audio file with the correct media type
|
261 |
# return FileResponse(renamed_audio_file)
|
|
|
38 |
"speaker_options": ["en","en-us","en-029","n-gb-x-gbclan","en-gb-x-rp","en-gb-scotland","en-gb-gbcwmd", "es", "de", "pl","ar","be","bn","bpy","bs","bg","ca","yue","hak","haw","cmn","hr","cs","da","nl","eo","et","fa","fa-latn","fi","fr-be","fr","ga","gd","ka","grc","el","kl","gn","gu","ht","he","hi","hu","id","io","it","ja","kn","kok","ko","ku","kk","ky","la","lb","ltg","lv","lfn","lt","jbo","mi","mk","ms","ml","mt","mr","nci","ne","nb","nog","or","om","pap","pt-br","pt","ro","ru","ru-lv","uk","sjn","sr","tn","sd","shn","si","sk","sl","es","es-419","sw","sv","ta","th","tk","tt","te","tr","ug","ur","uz","vi-vn-x-central","vi","vi0vn-x-south"],
|
39 |
"default_speaker": "en",
|
40 |
}
|
41 |
+
#@app.get("/", response_class=HTMLResponse)
|
42 |
+
#async def read_root(request: Request):
|
43 |
+
# return templates.TemplateResponse("interface.html", {"request": request, "data": data})
|
44 |
|
45 |
import json
|
46 |
import logging
|
|
|
114 |
#@app.post("/", response_class=FileResponse)
|
115 |
@app.post("/", response_class=HTMLResponse)
|
116 |
async def main(
|
|
|
117 |
text_input: str = Form(...),
|
118 |
speaker: str = Form(...),
|
119 |
speed_slider: float = Form(...),
|
120 |
noise_scale_slider: float = Form(...),
|
121 |
noise_scale_w_slider: float = Form(...),
|
122 |
+
play: bool = Form(True),
|
123 |
+
request: Request
|
124 |
):
|
125 |
"""Main entry point"""
|
126 |
sys.path.append('./content/piper/src/python')
|
|
|
148 |
playaudio("novoices")
|
149 |
raise Exception(lan.translate(lang, "No downloaded voice packages!"))
|
150 |
elif isinstance(onnx_models, str):
|
151 |
+
# Show loading message and disable the form
|
152 |
+
response_html = """
|
153 |
+
<div id="loading-message">Generating your audio, please wait...</div>
|
154 |
+
<script>
|
155 |
+
document.getElementById("synthesize_button").disabled = true;
|
156 |
+
</script>
|
157 |
+
"""
|
158 |
onnx_model = onnx_models
|
159 |
model, config = load_onnx(onnx_model, sess_options, providers)
|
160 |
config["espeak"]["voice"] = speaker
|
|
|
202 |
|
203 |
# Create a URL to download the file
|
204 |
file_url = f'/download?fileId={file_id}'
|
205 |
+
# Restore the form and return the response
|
206 |
+
response_html += """
|
207 |
+
<script>
|
208 |
+
document.getElementById("loading-message").innerText = "Audio generated successfully!";
|
209 |
+
document.getElementById("synthesize_button").disabled = false;
|
210 |
+
</script>
|
211 |
+
"""
|
212 |
# os.rename(temp_audio_file, renamed_audio_file)
|
213 |
|
214 |
# Specify the path to your MP3 audio file
|
|
|
269 |
|
270 |
|
271 |
# Save the audio as a temporary WAV file
|
272 |
+
return templates.TemplateResponse("interface.html", {"request": request, "file_url": file_url, "data": data, "dynamic_content": response_html})
|
273 |
|
274 |
# Serve the audio file with the correct media type
|
275 |
# return FileResponse(renamed_audio_file)
|