radinhas commited on
Commit
9062b52
1 Parent(s): 13533c1

Update apis/chat_api.py

Browse files
Files changed (1) hide show
  1. 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
- audioobj = gTTS(text = item.input_text,
106
- lang = item.from_language,
107
- slow = False)
108
- fileName = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(10));
109
- fileName = fileName + ".mp3";
110
- mp3_fp = BytesIO()
111
- #audioobj.save(fileName)
112
- audioobj.write_to_fp(mp3_fp)
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):
 
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):