radinhas commited on
Commit
b240a3f
1 Parent(s): c36683d

Update apis/chat_api.py

Browse files
Files changed (1) hide show
  1. apis/chat_api.py +4 -4
apis/chat_api.py CHANGED
@@ -9,7 +9,7 @@ import base64
9
 
10
  from fastapi import FastAPI, Response
11
  from fastapi.encoders import jsonable_encoder
12
- from fastapi.responses import JSONResponse
13
  from pydantic import BaseModel, Field
14
  from sse_starlette.sse import EventSourceResponse
15
  from utils.logger import logger
@@ -108,12 +108,12 @@ class ChatAPIApp:
108
  fileName = fileName + ".mp3";
109
  mp3_fp = BytesIO()
110
  #audioobj.save(fileName)
111
- audioobj.write_to_fp(mp3_fp)
112
- buffer = bytearray(mp3_fp.read())
113
  #base64EncodedStr = base64.encodebytes(buffer)
114
  #mp3_fp.read()
115
  #return Response(content=mp3_fp.tell(), media_type="audio/mpeg")
116
- return buffer
117
  except:
118
  item_response = {
119
  "status": 400
 
9
 
10
  from fastapi import FastAPI, Response
11
  from fastapi.encoders import jsonable_encoder
12
+ from fastapi.responses import JSONResponse, StreamingResponse
13
  from pydantic import BaseModel, Field
14
  from sse_starlette.sse import EventSourceResponse
15
  from utils.logger import logger
 
108
  fileName = fileName + ".mp3";
109
  mp3_fp = BytesIO()
110
  #audioobj.save(fileName)
111
+ #audioobj.write_to_fp(mp3_fp)
112
+ #buffer = bytearray(mp3_fp.read())
113
  #base64EncodedStr = base64.encodebytes(buffer)
114
  #mp3_fp.read()
115
  #return Response(content=mp3_fp.tell(), media_type="audio/mpeg")
116
+ return StreamingResponse(audioobj.stream())
117
  except:
118
  item_response = {
119
  "status": 400