1MR commited on
Commit
16d6bcd
·
verified ·
1 Parent(s): 4f46fca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -41,17 +41,18 @@ def text_to_pcm_array(text: str) -> str:
41
 
42
 
43
  # ---------- ENDPOINT ----------
44
- @app.post("/send_message_recive_pcm", response_class=PlainTextResponse)
45
- async def send_message_recive_pcm(message: str = Form(...)):
46
- pcm_array = text_to_pcm_array(message)
47
- return pcm_array
48
-
49
- # from pydantic import BaseModel
50
 
51
- # class Request(BaseModel):
52
- # message: str
53
 
54
- # @app.post("/send_message_recive_pcm", response_class=PlainTextResponse)
55
- # async def send_message_recive_pcm(req: Request):
56
- # pcm_array = text_to_pcm_array(req.message)
57
- # return pcm_array
 
 
 
 
41
 
42
 
43
  # ---------- ENDPOINT ----------
44
+ # @app.post("/send_message_recive_pcm", response_class=PlainTextResponse)
45
+ # async def send_message_recive_pcm(message: str = Form(...)):
46
+ # pcm_array = text_to_pcm_array(message)
47
+ # return pcm_array
 
 
48
 
49
+ from fastapi.responses import StreamingResponse
50
+ import io
51
 
52
+ @app.post("/send_message_recive_pcm")
53
+ async def send_message_recive_pcm(message: str = Form(...)):
54
+ pcm_array = text_to_pcm_array(message) # numpy array dtype=int16
55
+ buf = io.BytesIO()
56
+ buf.write(pcm_array.tobytes())
57
+ buf.seek(0)
58
+ return StreamingResponse(buf, media_type="application/octet-stream")