Mp3 uploading is now done on next, now doing concurrent reading and listening exercise calls with ayncio's gather to openai, should be faster
This commit is contained in:
@@ -15,7 +15,3 @@ class IListeningController(ABC):
|
||||
@abstractmethod
|
||||
async def generate_mp3(self, dto):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def save_listening(self, data):
|
||||
pass
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import io
|
||||
|
||||
from starlette.responses import StreamingResponse
|
||||
|
||||
from app.controllers.abc import IListeningController
|
||||
from app.dtos.listening import SaveListeningDTO, GenerateListeningExercises, Dialog
|
||||
from app.dtos.listening import GenerateListeningExercises, Dialog
|
||||
from app.services.abc import IListeningService
|
||||
from fastapi import Response
|
||||
|
||||
|
||||
class ListeningController(IListeningController):
|
||||
@@ -17,13 +20,12 @@ class ListeningController(IListeningController):
|
||||
|
||||
async def generate_mp3(self, dto: Dialog):
|
||||
mp3 = await self._service.generate_mp3(dto)
|
||||
return Response(
|
||||
content=mp3,
|
||||
|
||||
return StreamingResponse(
|
||||
content=io.BytesIO(mp3),
|
||||
media_type="audio/mpeg",
|
||||
headers={
|
||||
"Content-Type": "audio/mpeg",
|
||||
"Content-Disposition": "attachment;filename=speech.mp3"
|
||||
}
|
||||
)
|
||||
|
||||
async def save_listening(self, data: SaveListeningDTO):
|
||||
return await self._service.save_listening(data.parts, data.minTimer, data.difficulty, data.id)
|
||||
|
||||
Reference in New Issue
Block a user