File size: 1,732 Bytes
dc315c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 flask import Flask, render_template, request
from elevenlabs import generate, set_api_key
import os
import subprocess

app = Flask(__name__)

# ✅ Set your ElevenLabs API key — store securely in real apps
set_api_key("sk_0be86a97d6cd7dd86b035694a0a607d3bb9466018b9090b7")

@app.route('/', methods=['GET', 'POST'])
def index():
    show_video = False
    if request.method == 'POST':
        text = request.form.get('text', '')

        if text.strip():
            # Generate speech audio
            audio = generate(
                text=text,
                voice="EXAVITQu4vr4xnSDxMaL",  # Default voice
                model="eleven_monolingual_v1"
            )

            # Save to MP3
            os.makedirs("static", exist_ok=True)
            audio_path = "static/output.mp3"
            with open(audio_path, "wb") as f:
                f.write(audio)

            # ✅ Generate a simple video with static avatar image
            image_path = "static/avatar.jpg"
            video_path = "static/talking_avatar.mp4"

            subprocess.run([
                "ffmpeg", "-y",
                "-loop", "1",
                "-i", image_path,
                "-i", audio_path,
                "-shortest",
                "-vf", "scale=640:480",
                "-c:v", "libx264",
                "-c:a", "aac",
                "-b:a", "192k",
                "-pix_fmt", "yuv420p",
                video_path
            ], check=True)

            show_video = True

    return render_template("index.html", show_video=show_video)

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=7860, debug=True)  # Custom port for Hugging Face or Replit