malek-messaoudii
Refactor audio processing to utilize free models and enhance logging; update TTS and STT services for improved functionality
95cb26e
raw
history blame
2.56 kB
from pydantic import BaseModel, Field
from typing import Optional
class STTResponse(BaseModel):
"""Response model for Speech-to-Text"""
text: str = Field(..., description="Transcribed text from audio")
model_name: str = Field(default="whisper-small", description="Model used")
language: Optional[str] = Field(default="en", description="Detected language")
duration_seconds: Optional[float] = Field(None, description="Audio duration")
class Config:
json_schema_extra = {
"example": {
"text": "hello how are you",
"model_name": "whisper-small",
"language": "en",
"duration_seconds": 3.2
}
}
class TTSRequest(BaseModel):
"""Request model for Text-to-Speech"""
text: str = Field(..., min_length=1, max_length=500, description="Text to convert to speech")
class Config:
json_schema_extra = {
"example": {
"text": "Hello, welcome to our AI voice system."
}
}
class TTSResponse(BaseModel):
"""Response model for Text-to-Speech"""
message: str = Field(..., description="Status message")
audio_format: str = Field(default="mp3", description="Audio format")
model_name: str = Field(default="gTTS", description="Model used")
length_seconds: Optional[float] = Field(None, description="Generated audio duration")
class Config:
json_schema_extra = {
"example": {
"message": "Audio generated successfully",
"audio_format": "mp3",
"model_name": "gTTS",
"length_seconds": 2.5
}
}
class ChatbotRequest(BaseModel):
"""Request model for Chatbot"""
text: str = Field(..., min_length=1, max_length=500, description="User query")
class Config:
json_schema_extra = {
"example": {
"text": "What is the weather today?"
}
}
class ChatbotResponse(BaseModel):
"""Response model for Chatbot"""
user_input: str = Field(..., description="User input text")
bot_response: str = Field(..., description="Bot response text")
model_name: str = Field(default="DialoGPT-medium", description="Model used")
class Config:
json_schema_extra = {
"example": {
"user_input": "Hello",
"bot_response": "Hi there! How can I help you?",
"model_name": "DialoGPT-medium"
}
}