Do0rMaMu commited on
Commit
c8c3aff
1 Parent(s): e423516

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -2
main.py CHANGED
@@ -3,6 +3,7 @@ from fastapi.responses import FileResponse
3
  import wave
4
  from piper.voice import PiperVoice
5
  import os
 
6
 
7
  app = FastAPI()
8
 
@@ -21,7 +22,8 @@ def synthesize_text(text: str = Form(...)):
21
  Returns:
22
  FileResponse: The WAV file containing the synthesized speech.
23
  """
24
- output_file = "output.wav"
 
25
 
26
  # Synthesize speech and save to a WAV file
27
  with wave.open(output_file, 'wb') as wav_file:
@@ -35,4 +37,4 @@ def synthesize_text(text: str = Form(...)):
35
 
36
  @app.get("/")
37
  def read_root():
38
- return {"message": "Welcome to the Piper TTS API. Use /synthesize/ to synthesize speech."}
 
3
  import wave
4
  from piper.voice import PiperVoice
5
  import os
6
+ import tempfile
7
 
8
  app = FastAPI()
9
 
 
22
  Returns:
23
  FileResponse: The WAV file containing the synthesized speech.
24
  """
25
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_file:
26
+ output_file = temp_file.name
27
 
28
  # Synthesize speech and save to a WAV file
29
  with wave.open(output_file, 'wb') as wav_file:
 
37
 
38
  @app.get("/")
39
  def read_root():
40
+ return {"message": "Welcome to the Piper TTS API. Use /synthesize/ to synthesize speech."}