Spaces:
Running
Running
Update apis/chat_api.py
Browse files- apis/chat_api.py +11 -13
apis/chat_api.py
CHANGED
@@ -102,23 +102,21 @@ class ChatAPIApp:
|
|
102 |
|
103 |
def text_to_speech(self, item: TTSPostItem):
|
104 |
try:
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
#base64EncodedStr = base64.encodebytes(buffer)
|
115 |
-
return Response(content=mp3_fp.read(), media_type="audio/mpeg")
|
116 |
except gtts.tts.gTTSError as err:
|
117 |
item_response = {
|
118 |
"status": 400
|
119 |
}
|
120 |
-
|
121 |
-
|
122 |
|
123 |
|
124 |
def setup_routes(self):
|
|
|
102 |
|
103 |
def text_to_speech(self, item: TTSPostItem):
|
104 |
try:
|
105 |
+
audioobj = gTTS(text = item.input_text, lang = item.from_language, slow = False)
|
106 |
+
fileName = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(10));
|
107 |
+
fileName = fileName + ".mp3";
|
108 |
+
mp3_fp = BytesIO()
|
109 |
+
#audioobj.save(fileName)
|
110 |
+
audioobj.write_to_fp(mp3_fp)
|
111 |
+
#buffer = bytearray(mp3_fp.read())
|
112 |
+
#base64EncodedStr = base64.encodebytes(buffer)
|
113 |
+
return Response(content=mp3_fp.read(), media_type="audio/mpeg")
|
|
|
|
|
114 |
except gtts.tts.gTTSError as err:
|
115 |
item_response = {
|
116 |
"status": 400
|
117 |
}
|
118 |
+
json_compatible_item_data = jsonable_encoder(item_response)
|
119 |
+
return JSONResponse(content=json_compatible_item_data)
|
120 |
|
121 |
|
122 |
def setup_routes(self):
|