File size: 2,654 Bytes
9bc318e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
API数据模型定义
包含所有API请求和响应的数据模型
"""

from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime


class TTSRequest(BaseModel):
    """TTS请求模型"""
    text: str = Field(..., description="要转换的文本", min_length=1, max_length=1000)
    character: str = Field(default="misono_mika", description="角色模型名称")
    speed: float = Field(default=1.0, description="语速倍率", ge=0.5, le=2.0)
    format: str = Field(default="wav", description="输出格式", pattern="^(wav|mp3)$")


class TTSResponse(BaseModel):
    """TTS响应模型"""
    success: bool
    message: str
    audio_url: Optional[str] = None
    duration: Optional[float] = None
    character: str
    timestamp: str


class VoiceCloneRequest(BaseModel):
    """语音克隆请求模型"""
    voice_name: str = Field(..., description="克隆声音名称", min_length=1, max_length=50)
    reference_audio_url: str = Field(..., description="参考音频文件URL或路径")
    reference_text: str = Field(..., description="参考音频对应的文本", min_length=3, max_length=500)
    description: Optional[str] = Field("", description="声音描述")


class AudioAnalysisResponse(BaseModel):
    """音频分析响应模型"""
    duration: float
    sample_rate: int
    quality_score: float
    recommendations: List[str]


class CharacterInfo(BaseModel):
    """角色信息模型"""
    name: str
    description: str
    type: str
    language: str
    model_size_mb: Optional[int] = None


class HealthResponse(BaseModel):
    """健康检查响应模型"""
    status: str
    version: str
    engine_status: str
    available_characters: List[str]
    predefined_characters: int
    custom_characters: int
    cloned_voices: int
    timestamp: str


class ErrorResponse(BaseModel):
    """错误响应模型"""
    success: bool = False
    error: str
    code: int
    timestamp: str


class BatchTTSResponse(BaseModel):
    """批量TTS响应模型"""
    success: bool
    results: List[dict]
    total: int
    completed: int
    timestamp: str


def create_success_response(message: str, data: dict = None) -> dict:
    """创建成功响应"""
    response = {
        "success": True,
        "message": message,
        "timestamp": datetime.now().isoformat()
    }
    if data:
        response.update(data)
    return response


def create_error_response(error: str, code: int = 500) -> dict:
    """创建错误响应"""
    return {
        "success": False,
        "error": error,
        "code": code,
        "timestamp": datetime.now().isoformat()
    }