hivecorp commited on
Commit
4cfd52e
·
verified ·
1 Parent(s): 4da00bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -77,17 +77,23 @@ def text_to_video(text, voice, rate, pitch, video_width, video_height, bg_color,
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
- draw(img) # Correct usage to apply the drawing
 
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)
93
  final_video_path = os.path.join(tempfile.gettempdir(), "output_video.mp4")
@@ -133,4 +139,4 @@ async def create_demo():
133
  # 运行应用
134
  if __name__ == "__main__":
135
  demo = asyncio.run(create_demo())
136
- demo.launch(share=True) # Set share=True to create a public link
 
77
  draw.fill_color = Color(text_color)
78
  draw.text_alignment = 'center'
79
  draw.text_interline_spacing = 10
80
+
81
  with Image(width=video_width, height=video_height, background=Color(bg_color)) as img:
82
  lines = page.split("\n")
83
+ # Centering text vertically
84
+ total_text_height = len(lines) * (text_size + 10) # Height of text area
85
+ start_y = (video_height - total_text_height) // 2 # Start position to center vertically
86
+
87
  for j, line in enumerate(lines):
88
+ draw.text(int(video_width / 2), start_y + (j * (text_size + 10)), line)
89
+
90
+ draw(img) # Apply the drawing to the image
91
  img.format = 'png'
92
  img_path = os.path.join(tempfile.gettempdir(), f"page_{i}.png")
93
  img.save(filename=img_path)
94
  text_clip = ImageClip(img_path).set_duration(audio_clip.duration).set_audio(audio_clip)
95
  video_clips.append(text_clip)
96
+
97
  # 合并所有视频片段
98
  final_video = concatenate_videoclips(video_clips)
99
  final_video_path = os.path.join(tempfile.gettempdir(), "output_video.mp4")
 
139
  # 运行应用
140
  if __name__ == "__main__":
141
  demo = asyncio.run(create_demo())
142
+ demo.launch()