mirror of
https://github.com/ijaric/voice_assistant.git
synced 2025-12-16 09:56:16 +00:00
feat: [#46] хендлер с рабочим stt
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
from .health import basic_router
|
||||
from .voice_responce_handler import VoiceResponseHandler
|
||||
|
||||
__all__ = ["basic_router"]
|
||||
__all__ = [
|
||||
"VoiceResponseHandler",
|
||||
"basic_router",
|
||||
]
|
||||
|
||||
28
src/assistant/lib/api/v1/handlers/voice_responce_handler.py
Normal file
28
src/assistant/lib/api/v1/handlers/voice_responce_handler.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import fastapi
|
||||
|
||||
import lib.models.tts.voice as models_tts_voice
|
||||
import lib.stt.services as stt_services
|
||||
|
||||
|
||||
class VoiceResponseHandler:
|
||||
def __init__(
|
||||
self,
|
||||
stt: stt_services.SpeechService,
|
||||
):
|
||||
self.stt = stt
|
||||
self.router = fastapi.APIRouter()
|
||||
self.router.add_api_route(
|
||||
"/",
|
||||
self.voice_response,
|
||||
methods=["POST"],
|
||||
summary="Ответ голосового помощника",
|
||||
description="Ответ голосового помощника",
|
||||
)
|
||||
|
||||
async def voice_response(
|
||||
self,
|
||||
voice: bytes = fastapi.File(...),
|
||||
voice_model: models_tts_voice.VoiceModelProvidersEnum = fastapi.Depends(),
|
||||
) -> dict[str, str]:
|
||||
voice_text: str = await self.stt.recognize(voice)
|
||||
return {"text": voice_text}
|
||||
@@ -1,3 +1,6 @@
|
||||
from .base import HealthResponse
|
||||
from .base import HealthResponse, VoiceResponse
|
||||
|
||||
__all__ = ["HealthResponse"]
|
||||
__all__ = [
|
||||
"HealthResponse",
|
||||
"VoiceResponse",
|
||||
]
|
||||
|
||||
@@ -3,3 +3,7 @@ import pydantic
|
||||
|
||||
class HealthResponse(pydantic.BaseModel):
|
||||
status: str = pydantic.Field(default=..., examples=["healthy"], description="Схема доступности сервиса")
|
||||
|
||||
|
||||
class VoiceResponse(pydantic.BaseModel):
|
||||
voice: bytes = pydantic.Field(default=..., description="Голосовой ответ")
|
||||
|
||||
Reference in New Issue
Block a user