| from app.mcp.decorators import mcp_tool |
| from pydantic import BaseModel, Field |
|
|
| from .core import get_video_audio_service |
|
|
|
|
| class VideoTranscriptionOutput(BaseModel): |
| success: bool = Field(description="是否成功") |
| text: str = Field(description="转录文本") |
| audio_path: str | None = Field(default=None, description="临时音频路径") |
| error: str | None = Field(default=None, description="错误信息") |
|
|
|
|
| @mcp_tool( |
| name="video-transcribe", |
| title="视频转录", |
| description="从 Base64 视频提取音频并转录为文本", |
| annotations={"readOnlyHint": True, "destructiveHint": False}, |
| ) |
| async def transcribe_video_base64( |
| video_base64: str, |
| suffix: str = ".mp4", |
| language: str | None = None, |
| ) -> VideoTranscriptionOutput: |
| result = get_video_audio_service().transcribe_video_base64( |
| video_base64, |
| suffix, |
| language, |
| ) |
| return VideoTranscriptionOutput(**result) |
|
|
|
|
| @mcp_tool( |
| name="video-file", |
| title="视频文件转录", |
| description="从本地视频文件提取音频并转录为文本", |
| annotations={"readOnlyHint": True, "destructiveHint": False}, |
| ) |
| async def transcribe_video_file( |
| video_path: str, |
| language: str | None = None, |
| ) -> VideoTranscriptionOutput: |
| result = get_video_audio_service().transcribe_video_file(video_path, language) |
| return VideoTranscriptionOutput(**result) |
|
|