Gregniuki commited on
Commit
09b7ce7
·
1 Parent(s): 34b4e53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -91,8 +91,8 @@ def detect_onnx_models(path):
91
  else:
92
  return None
93
 
94
- #@app.post("/synthesize")
95
- @app.post("/synthesize", response_class=FileResponse)
96
  async def main(
97
  request: Request,
98
  text_input: str = Form(...),
@@ -189,10 +189,9 @@ async def main(
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
- temp_audio_path = os.path.join(tempfile.gettempdir(), "generated_audio.wav")
193
- sf.write(temp_audio_path, merged_audio, config["audio"]["sample_rate"])
194
- return FileResponse(temp_audio_path)
195
- # return {"message": f"Text to synthesize: {text_input}, Speed: {speed_slider}, Play: {play}"}
196
 
197
  def load_onnx(model, sess_options, providers = ["CPUExecutionProvider"]):
198
  _LOGGER.debug("Loading model from %s", model)
@@ -242,6 +241,7 @@ def phonemes_to_ids(config, phonemes: List[str]) -> List[int]:
242
  ids.extend(id_map[EOS])
243
  return ids
244
 
 
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":
@@ -276,7 +276,9 @@ def inferencing(model, config, sid, line, length_scale = 1, noise_scale = 0.667,
276
  audios.append(audio)
277
  merged_audio = np.concatenate(audios)
278
  sample_rate = config["audio"]["sample_rate"]
279
-
 
 
280
  # Return the audio file as a FastAPI response
281
  # display(Markdown(f"{line}"))
282
  # display(Audio(merged_audio, rate=sample_rate, autoplay=auto_play))
 
91
  else:
92
  return None
93
 
94
+ @app.post("/synthesize")
95
+ #@app.post("/synthesize", response_class=FileResponse)
96
  async def main(
97
  request: Request,
98
  text_input: str = Form(...),
 
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 {"message": "Post request received", "data": data}
193
+
194
+ # return {"message": f"Text to synthesize: {text_input}, Speed: {speed_slider}, Play: {play}"}
 
195
 
196
  def load_onnx(model, sess_options, providers = ["CPUExecutionProvider"]):
197
  _LOGGER.debug("Loading model from %s", model)
 
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":
 
276
  audios.append(audio)
277
  merged_audio = np.concatenate(audios)
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
+ return FileResponse(temp_audio_path)
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))