Spaces:
Running
Running
Update apis/chat_api.py
Browse files- apis/chat_api.py +8 -0
apis/chat_api.py
CHANGED
@@ -101,6 +101,7 @@ class ChatAPIApp:
|
|
101 |
)
|
102 |
|
103 |
def text_to_speech(self, item: TTSPostItem):
|
|
|
104 |
audioobj = gTTS(text = item.input_text,
|
105 |
lang = item.from_language,
|
106 |
slow = False)
|
@@ -112,6 +113,13 @@ class ChatAPIApp:
|
|
112 |
#buffer = bytearray(mp3_fp.read())
|
113 |
#base64EncodedStr = base64.encodebytes(buffer)
|
114 |
return Response(content=mp3_fp.read(), media_type="audio/mpeg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
def setup_routes(self):
|
117 |
for prefix in ["", "/v1"]:
|
|
|
101 |
)
|
102 |
|
103 |
def text_to_speech(self, item: TTSPostItem):
|
104 |
+
try:
|
105 |
audioobj = gTTS(text = item.input_text,
|
106 |
lang = item.from_language,
|
107 |
slow = False)
|
|
|
113 |
#buffer = bytearray(mp3_fp.read())
|
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 |
+
json_compatible_item_data = jsonable_encoder(item_response)
|
121 |
+
return JSONResponse(content=json_compatible_item_data)
|
122 |
+
|
123 |
|
124 |
def setup_routes(self):
|
125 |
for prefix in ["", "/v1"]:
|