Spaces:
Running
Running
Update apis/chat_api.py
Browse files- apis/chat_api.py +7 -3
apis/chat_api.py
CHANGED
@@ -4,6 +4,7 @@ import sys
|
|
4 |
import json
|
5 |
import string
|
6 |
import random
|
|
|
7 |
|
8 |
|
9 |
from fastapi import FastAPI
|
@@ -15,6 +16,7 @@ from utils.logger import logger
|
|
15 |
from networks.message_streamer import MessageStreamer
|
16 |
from messagers.message_composer import MessageComposer
|
17 |
from googletrans import Translator
|
|
|
18 |
from gtts import gTTS
|
19 |
|
20 |
|
@@ -104,10 +106,12 @@ class ChatAPIApp:
|
|
104 |
slow = False)
|
105 |
fileName = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(10));
|
106 |
fileName = fileName + ".mp3";
|
107 |
-
|
108 |
-
|
|
|
|
|
109 |
item_response = {
|
110 |
-
"src":
|
111 |
}
|
112 |
json_compatible_item_data = jsonable_encoder(item_response)
|
113 |
return JSONResponse(content=json_compatible_item_data)
|
|
|
4 |
import json
|
5 |
import string
|
6 |
import random
|
7 |
+
import base64
|
8 |
|
9 |
|
10 |
from fastapi import FastAPI
|
|
|
16 |
from networks.message_streamer import MessageStreamer
|
17 |
from messagers.message_composer import MessageComposer
|
18 |
from googletrans import Translator
|
19 |
+
from io import BytesIO
|
20 |
from gtts import gTTS
|
21 |
|
22 |
|
|
|
106 |
slow = False)
|
107 |
fileName = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(10));
|
108 |
fileName = fileName + ".mp3";
|
109 |
+
mp3_fp = BytesIO()
|
110 |
+
#audioobj.save(fileName)
|
111 |
+
audioobj.write_to_fp(mp3_fp)
|
112 |
+
base64EncodedStr = base64.b64encode(mp3_fp)
|
113 |
item_response = {
|
114 |
+
"src": base64EncodedStr
|
115 |
}
|
116 |
json_compatible_item_data = jsonable_encoder(item_response)
|
117 |
return JSONResponse(content=json_compatible_item_data)
|