File size: 1,404 Bytes
ecc51ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from gtts import gTTS
from PIL import Image, ImageDraw, ImageFont
import moviepy.editor as mpy

def process_text(text):
    lines = text.strip().split("\n")
    dialogue = []
    for line in lines:
        if ":" in line:
            name, speech = line.split(":", 1)
            dialogue.append((name.strip(), speech.strip()))
    return dialogue

def generate_audio(text):
    tts = gTTS(text=text, lang='ar')
    path = "/tmp/audio.mp3"
    tts.save(path)
    return path

def generate_image(text):
    img = Image.new('RGB', (1280, 720), color=(255, 255, 255))
    d = ImageDraw.Draw(img)
    fnt = ImageFont.load_default()
    d.text((10, 10), text, font=fnt, fill=(0, 0, 0))
    path = "/tmp/image.png"
    img.save(path)
    return path

def generate_video(text, avatars):
    clips = []
    for name, speech in process_text(text):
        img = Image.new('RGB', (1280, 720), color=(0, 0, 0))
        d = ImageDraw.Draw(img)
        d.text((20, 650), f"{name}: {speech}", fill=(255, 255, 255))
        # إضافة العلامة المائية
        logo = "mostafa gouda"
        d.text((1000, 690), logo, fill=(180, 180, 180))
        frame = "/tmp/frame.png"
        img.save(frame)
        clip = mpy.ImageClip(frame).set_duration(3)
        clips.append(clip)
    final = mpy.concatenate_videoclips(clips)
    path = "/tmp/final.mp4"
    final.write_videofile(path, fps=24)
    return path