File size: 1,589 Bytes
1fe9360
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from mcp.server.fastmcp import FastMCP
from localizer_engine import process_video_sync
import os

# Initialize MCP Server
mcp = FastMCP("Global Video Localizer")

@mcp.tool()
def localize_video_file(
    file_path: str,
    target_language: str = "es",
    elevenlabs_api_key: str | None = None,
) -> str:
    """
    Localizes a video file into a target language.
    
    Args:
        file_path: Absolute path to the video file (.mp4)
        target_language: Language code (es, fr, de, it, ja, zh, hi, ar)
        elevenlabs_api_key: Optional API key for premium ElevenLabs voices (not persisted)
        
    Returns:
        Path to the localized video file and summary.
    """
    if not os.path.exists(file_path):
        return f"Error: File not found at {file_path}"
        
    # Use safe synchronous wrapper
    try:
        output_path, orig, trans = process_video_sync(
            file_path,
            target_language,
            elevenlabs_api_key=elevenlabs_api_key,
        )
        
        if output_path:
            return f"""✅ Video localization successful!

Target Language: {target_language}
Original Text: {orig[:100]}...
Translated Text: {trans[:100]}...

Output saved to: {output_path}
"""
        else:
            return f"❌ Error processing video: {orig}"
            
    except Exception as e:
        return f"❌ Critical Error: {str(e)}"

if __name__ == "__main__":
    print("Starting Global Video Localizer MCP Server...")
    print("✨ Features: Whisper transcription + Qwen translation + Edge TTS + Audio time-stretching")
    mcp.run()