Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,12 @@ import logging
|
|
21 |
|
22 |
app = FastAPI()
|
23 |
templates = Jinja2Templates(directory="templates")
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
# Configure logging
|
26 |
logging.basicConfig(level=logging.DEBUG)
|
27 |
# Mock data for your interface
|
@@ -186,10 +191,17 @@ async def main(
|
|
186 |
noise_scale = noise_scale_slider.value
|
187 |
noise_scale_w = noise_scale_w_slider.value
|
188 |
auto_play = play.value
|
189 |
-
inferencing(model, config, sid, text, rate, noise_scale, noise_scale_w, auto_play)
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
|
191 |
# Save the audio as a temporary WAV file
|
192 |
-
return {"
|
|
|
193 |
|
194 |
# return {"message": f"Text to synthesize: {text_input}, Speed: {speed_slider}, Play: {play}"}
|
195 |
|
@@ -241,7 +253,6 @@ def phonemes_to_ids(config, phonemes: List[str]) -> List[int]:
|
|
241 |
ids.extend(id_map[EOS])
|
242 |
return ids
|
243 |
|
244 |
-
@app.get("/generate_audio")
|
245 |
def inferencing(model, config, sid, line, length_scale = 1, noise_scale = 0.667, noise_scale_w = 0.8, auto_play=True):
|
246 |
audios = []
|
247 |
if config["phoneme_type"] == "PhonemeType.ESPEAK":
|
@@ -278,7 +289,9 @@ def inferencing(model, config, sid, line, length_scale = 1, noise_scale = 0.667,
|
|
278 |
sample_rate = config["audio"]["sample_rate"]
|
279 |
temp_audio_path = os.path.join(tempfile.gettempdir(), "generated_audio.wav")
|
280 |
sf.write(temp_audio_path, merged_audio, config["audio"]["sample_rate"])
|
281 |
-
|
|
|
|
|
282 |
# Return the audio file as a FastAPI response
|
283 |
# display(Markdown(f"{line}"))
|
284 |
# display(Audio(merged_audio, rate=sample_rate, autoplay=auto_play))
|
@@ -376,14 +389,12 @@ def transform(input_data):
|
|
376 |
|
377 |
return magnitude, phase
|
378 |
|
379 |
-
@app.get("/", response_class=HTMLResponse)
|
380 |
-
async def read_root(request: Request):
|
381 |
-
return templates.TemplateResponse(
|
382 |
-
"interface.html",
|
383 |
-
{"request": request, "data": data},
|
384 |
-
)
|
385 |
|
386 |
|
|
|
|
|
|
|
|
|
387 |
if __name__ == "__main__":
|
388 |
# main()
|
389 |
import uvicorn
|
|
|
21 |
|
22 |
app = FastAPI()
|
23 |
templates = Jinja2Templates(directory="templates")
|
24 |
+
@app.get("/", response_class=HTMLResponse)
|
25 |
+
async def read_root(request: Request):
|
26 |
+
return templates.TemplateResponse(
|
27 |
+
"interface.html",
|
28 |
+
{"request": request, "data": data},
|
29 |
+
)
|
30 |
# Configure logging
|
31 |
logging.basicConfig(level=logging.DEBUG)
|
32 |
# Mock data for your interface
|
|
|
191 |
noise_scale = noise_scale_slider.value
|
192 |
noise_scale_w = noise_scale_w_slider.value
|
193 |
auto_play = play.value
|
194 |
+
audio = inferencing(model, config, sid, text, rate, noise_scale, noise_scale_w, auto_play)
|
195 |
+
temp_audio_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
|
196 |
+
audio.export(temp_audio_file.name, format="mp3")
|
197 |
+
|
198 |
+
# Rename the temporary audio file based on the text input
|
199 |
+
renamed_audio_file = os.path.join(tempfile.gettempdir(), f"{text_input}.mp3")
|
200 |
+
os.rename(temp_audio_file.name, renamed_audio_file)
|
201 |
|
202 |
# Save the audio as a temporary WAV file
|
203 |
+
return templates.TemplateResponse("interface.html", {"request": request, "audio_file": renamed_audio_file})
|
204 |
+
|
205 |
|
206 |
# return {"message": f"Text to synthesize: {text_input}, Speed: {speed_slider}, Play: {play}"}
|
207 |
|
|
|
253 |
ids.extend(id_map[EOS])
|
254 |
return ids
|
255 |
|
|
|
256 |
def inferencing(model, config, sid, line, length_scale = 1, noise_scale = 0.667, noise_scale_w = 0.8, auto_play=True):
|
257 |
audios = []
|
258 |
if config["phoneme_type"] == "PhonemeType.ESPEAK":
|
|
|
289 |
sample_rate = config["audio"]["sample_rate"]
|
290 |
temp_audio_path = os.path.join(tempfile.gettempdir(), "generated_audio.wav")
|
291 |
sf.write(temp_audio_path, merged_audio, config["audio"]["sample_rate"])
|
292 |
+
audio = AudioSegment.from_mp3(temp_audio_path)
|
293 |
+
return audio
|
294 |
+
# return FileResponse(temp_audio_path)
|
295 |
# Return the audio file as a FastAPI response
|
296 |
# display(Markdown(f"{line}"))
|
297 |
# display(Audio(merged_audio, rate=sample_rate, autoplay=auto_play))
|
|
|
389 |
|
390 |
return magnitude, phase
|
391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
|
393 |
|
394 |
+
#@app.get("/")
|
395 |
+
#async def read_root(request: Request):
|
396 |
+
# return templates.TemplateResponse("interface.html", {"request": request})
|
397 |
+
|
398 |
if __name__ == "__main__":
|
399 |
# main()
|
400 |
import uvicorn
|