Blackbox melotts updated

This commit is contained in:
gdw6463
2024-05-17 16:19:07 +08:00
parent 4ffa38592c
commit f2d87ec1ea

View File

@ -26,12 +26,15 @@ class MeloTTS(Blackbox):
text = args[0] text = args[0]
return isinstance(text, str) return isinstance(text, str)
def processing(self, *args, **kwargs) -> io.BytesIO: def processing(self, *args, **kwargs) -> bytes:
text = args[0] text = args[0]
current_time = time.time() current_time = time.time()
audio = self.tts_service.read(text) message = {
"text": text
}
response = requests.post(self.melotts, json=message)
print("#### MeloTTS Service consume : ", (time.time()-current_time)) print("#### MeloTTS Service consume : ", (time.time()-current_time))
return audio return response.content
async def fast_api_handler(self, request: Request) -> Response: async def fast_api_handler(self, request: Request) -> Response:
try: try:
@ -41,7 +44,6 @@ class MeloTTS(Blackbox):
text = data.get("text") text = data.get("text")
if text is None: if text is None:
return JSONResponse(content={"error": "text is required"}, status_code=status.HTTP_400_BAD_REQUEST) return JSONResponse(content={"error": "text is required"}, status_code=status.HTTP_400_BAD_REQUEST)
by = self.processing(text) return Response(content=self.processing(text), media_type="audio/wav", headers={"Content-Disposition": "attachment; filename=audio.wav"})
return Response(content=by.read(), media_type="audio/mp3", headers={"Content-Disposition": "attachment; filename=audio.mp3"})