hivecorp commited on
Commit
75a0f9c
·
verified ·
1 Parent(s): 1995443

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -71,30 +71,22 @@ def text_to_video(text, voice, rate, pitch, video_width, video_height, bg_color,
71
  audio_clips.append(audio_clip)
72
 
73
  # 使用 wand 生成视频片段
74
- with Drawing() as draw: # Ensure this block is indented properly
75
- draw.font = font_path # Indent this line with 4 spaces
76
- draw.font_size = text_size
77
- draw.fill_color = Color(text_color)
78
- draw.text_alignment = 'center'
79
- draw.text_interline_spacing = 10
80
-
81
- # Create the image with another 'with' block, indented
82
- with Image(width=video_width, height=video_height, background=Color(bg_color)) as img:
83
- lines = page.split("\n")
84
- for j, line in enumerate(lines):
85
- draw.text(int(video_width / 2), (j + 1) * (text_size + 10), line)
86
-
87
- # Apply the drawing to the image
88
- draw(img)
89
-
90
- # Save the image as a PNG file
91
- img.format = 'png'
92
- img_path = os.path.join(tempfile.gettempdir(), f"page_{i}.png")
93
- img.save(filename=img_path)
94
-
95
- # Create the video clip using the generated image
96
- text_clip = ImageClip(img_path).set_duration(audio_clip.duration).set_audio(audio_clip)
97
- video_clips.append(text_clip)
98
 
99
  # 合并所有视频片段
100
  final_video = concatenate_videoclips(video_clips)
 
71
  audio_clips.append(audio_clip)
72
 
73
  # 使用 wand 生成视频片段
74
+ with Drawing() as draw:
75
+ draw.font = font_path
76
+ draw.font_size = text_size
77
+ draw.fill_color = Color(text_color)
78
+ draw.text_alignment = 'center'
79
+ draw.text_interline_spacing = 10
80
+ with Image(width=video_width, height=video_height, background=Color(bg_color)) as img:
81
+ lines = page.split("\n")
82
+ for j, line in enumerate(lines):
83
+ draw.text(int(video_width / 2), (j + 1) * (text_size + 10), line)
84
+ img.draw(draw)
85
+ img.format = 'png'
86
+ img_path = os.path.join(tempfile.gettempdir(), f"page_{i}.png")
87
+ img.save(filename=img_path)
88
+ text_clip = ImageClip(img_path).set_duration(audio_clip.duration).set_audio(audio_clip)
89
+ video_clips.append(text_clip)
 
 
 
 
 
 
 
 
90
 
91
  # 合并所有视频片段
92
  final_video = concatenate_videoclips(video_clips)