randusertry commited on
Commit
b73472b
·
verified ·
1 Parent(s): 438f708

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -7,6 +7,7 @@ import scipy.io.wavfile
7
  from fastapi import FastAPI, UploadFile, File, HTTPException
8
  from fastapi.responses import StreamingResponse
9
  from fastapi.responses import FileResponse
 
10
  from pydantic import BaseModel
11
  from faster_whisper import WhisperModel
12
  from transformers import VitsModel, AutoTokenizer
@@ -111,15 +112,18 @@ async def text_to_speech(request: TTSRequest):
111
  # Get the bytes and manually ensure the buffer is ready
112
  content = buffer.getvalue()
113
  buffer.close()
114
-
115
- return StreamingResponse(
116
- io.BytesIO(content),
 
117
  media_type="audio/wav",
118
  headers={
119
- "Content-Disposition": "inline; filename=speech.wav",
120
- "Content-Length": str(len(content)) # Tell the browser exactly how much data to expect
 
121
  }
122
  )
 
123
 
124
  @app.get("/health")
125
  def health():
 
7
  from fastapi import FastAPI, UploadFile, File, HTTPException
8
  from fastapi.responses import StreamingResponse
9
  from fastapi.responses import FileResponse
10
+ from fastapi import Response
11
  from pydantic import BaseModel
12
  from faster_whisper import WhisperModel
13
  from transformers import VitsModel, AutoTokenizer
 
112
  # Get the bytes and manually ensure the buffer is ready
113
  content = buffer.getvalue()
114
  buffer.close()
115
+
116
+
117
+ return Response(
118
+ content=content,
119
  media_type="audio/wav",
120
  headers={
121
+ "Content-Disposition": "attachment; filename=speech.wav",
122
+ "Content-Length": str(len(content)),
123
+ "Access-Control-Expose-Headers": "Content-Disposition" # Crucial for CORS/Proxy
124
  }
125
  )
126
+
127
 
128
  @app.get("/health")
129
  def health():