Spaces:
Configuration error
Configuration error
| 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 |