| from app.mcp.decorators import mcp_tool |
| from pydantic import BaseModel, Field |
|
|
| from .core import get_transcription_service |
|
|
|
|
| class TranscriptionOutput(BaseModel): |
| success: bool = Field(description="是否成功") |
| text: str = Field(description="转录文本") |
| segments: list = Field(default_factory=list, description="分段结果") |
| error: str | None = Field(default=None, description="错误信息") |
|
|
|
|
| @mcp_tool( |
| name="audio-transcribe", |
| title="音频转录", |
| description="将 Base64 音频转录为文本", |
| annotations={"readOnlyHint": True, "destructiveHint": False}, |
| ) |
| async def transcribe_audio_base64( |
| audio_base64: str, |
| suffix: str = ".wav", |
| language: str | None = None, |
| ) -> TranscriptionOutput: |
| result = get_transcription_service().transcribe_base64( |
| audio_base64, |
| suffix, |
| language, |
| ) |
| return TranscriptionOutput(**result) |
|
|
|
|
| @mcp_tool( |
| name="audio-file", |
| title="音频文件转录", |
| description="将本地音频文件转录为文本", |
| annotations={"readOnlyHint": True, "destructiveHint": False}, |
| ) |
| async def transcribe_audio_file( |
| audio_path: str, |
| language: str | None = None, |
| ) -> TranscriptionOutput: |
| result = get_transcription_service().transcribe_file(audio_path, language) |
| return TranscriptionOutput(**result) |
|
|