e29a698325
Deploy / Build Production Runtime Images (push) Has been skipped
Deploy / Deploy Production (push) Has been skipped
Deploy / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 169h43m28s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 169h43m33s
Deploy / Deploy Staging (push) Failing after 169h47m22s
CI/CD Pipeline / Frontend Lint (push) Failing after 169h47m58s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 169h48m6s
- POST /api/v1/tts/synthesize: create TTS job (status=pending)
- GET /api/v1/tts/jobs: list user's jobs (page/page_size pagination)
- GET /api/v1/tts/jobs/{job_id}: get job details
- GET /api/v1/tts/jobs/{job_id}/status: query status for polling
- DELETE /api/v1/tts/jobs/{job_id}: delete job (soft delete)
Includes:
- Schema: TTSSynthesizeRequest, TTSJobResponse, ListTTSJobResponse, TTSStatusResponse
- Use Cases: CreateTTSJob, ListTTSJobs, GetTTSJob, GetTTSJobStatus, DeleteTTSJob
- SQLAlchemy adapter: SQLAlchemyTTSJobRepository
- ORM model: TTSJobModel
- Alembic migration: 020_add_tts_jobs_table
- Unit tests: 14 tests covering all use cases
CosyVoice API calls deferred to task 3.07.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
90 lines
2.3 KiB
Python
90 lines
2.3 KiB
Python
"""TTS 合成 API Schema。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from datetime import datetime
|
||
from typing import Any, Dict, List, Optional
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
class TTSSynthesizeRequest(BaseModel):
|
||
"""TTS 合成请求。"""
|
||
|
||
text: str = Field(..., min_length=1, max_length=10000, description="合成文本")
|
||
voice_id: str = Field("", description="音色 ID")
|
||
output_name: str = Field("", description="输出文件名")
|
||
language: str = Field("zh-CN", description="语言")
|
||
speed: float = Field(1.0, ge=0.5, le=2.0, description="语速")
|
||
voice_model: str = Field("", description="语音模型名称")
|
||
voice_clone_profile_id: str = Field("", description="关联的音色克隆档案 ID")
|
||
format: str = Field("mp3", description="输出格式(mp3/wav/pcm)")
|
||
metadata_: Optional[Dict[str, Any]] = Field(
|
||
default=None, alias="metadata", description="额外元数据"
|
||
)
|
||
|
||
class Config:
|
||
populate_by_name = True
|
||
|
||
|
||
class TTSJobResponse(BaseModel):
|
||
"""TTS 任务响应。"""
|
||
|
||
id: str
|
||
user_id: str
|
||
input_text: str
|
||
voice_id: str = ""
|
||
voice_model: str = ""
|
||
project_id: str = ""
|
||
voice_clone_profile_id: str = ""
|
||
status: str
|
||
output_audio_url: str = ""
|
||
output_audio_key: str = ""
|
||
duration: float = 0.0
|
||
file_size: int = 0
|
||
sample_rate: int = 22050
|
||
format: str = "mp3"
|
||
error_message: str = ""
|
||
retry_count: int = 0
|
||
max_retries: int = 3
|
||
metadata_: Optional[Dict[str, Any]] = Field(
|
||
default=None, alias="metadata", description="额外元数据"
|
||
)
|
||
started_at: Optional[datetime] = None
|
||
completed_at: Optional[datetime] = None
|
||
created_at: datetime
|
||
updated_at: datetime
|
||
|
||
class Config:
|
||
populate_by_name = True
|
||
|
||
|
||
class TTSStatusResponse(BaseModel):
|
||
"""TTS 任务状态响应(用于轮询)。"""
|
||
|
||
id: str
|
||
status: str
|
||
output_audio_url: str = ""
|
||
error_message: str = ""
|
||
duration: float = 0.0
|
||
retry_count: int = 0
|
||
created_at: datetime
|
||
updated_at: datetime
|
||
|
||
|
||
class TTSSynthesizeResponse(BaseModel):
|
||
"""TTS 合成创建响应。"""
|
||
|
||
job_id: str
|
||
status: str
|
||
message: str = "合成任务已创建"
|
||
|
||
|
||
class ListTTSJobResponse(BaseModel):
|
||
"""TTS 任务列表响应。"""
|
||
|
||
items: List[TTSJobResponse]
|
||
total: int
|
||
page: int
|
||
page_size: int
|