rogerxavier
commited on
Commit
•
733839a
1
Parent(s):
ff815b0
Update 3mergeDialogToVideo.py
Browse files- 3mergeDialogToVideo.py +17 -13
3mergeDialogToVideo.py
CHANGED
@@ -126,7 +126,7 @@ def get_sorted_dialog_text(image_path:"包含后缀的文件路径")->"返回排
|
|
126 |
|
127 |
|
128 |
#通过文字获取音频
|
129 |
-
def get_audio_data(text:str)-> "返回audio data io句柄, duration":
|
130 |
# Creates an instance of a speech config with specified subscription key and service region.
|
131 |
speech_key = azure_speech_key
|
132 |
service_region = azure_service_region
|
@@ -167,6 +167,7 @@ def get_audio_data(text:str)-> "返回audio data io句柄, duration":
|
|
167 |
|
168 |
else:
|
169 |
print("Error: Failed to synthesize audio. Status code:", response.status_code)
|
|
|
170 |
|
171 |
|
172 |
|
@@ -276,18 +277,21 @@ if __name__ == '__main__':
|
|
276 |
|
277 |
##获取当前图片对应的临时音频文件名称和文案时长
|
278 |
filename, duration = get_audio_data(cur_copywrite)
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
|
|
|
|
|
|
291 |
else:
|
292 |
pass ##图片不规范直接跳过
|
293 |
video = concatenate_videoclips(video_clips)
|
|
|
126 |
|
127 |
|
128 |
#通过文字获取音频
|
129 |
+
def get_audio_data(text:str)-> "返回audio data io句柄, duration(也有可能包含无效字符导致生成音频400错误)":
|
130 |
# Creates an instance of a speech config with specified subscription key and service region.
|
131 |
speech_key = azure_speech_key
|
132 |
service_region = azure_service_region
|
|
|
167 |
|
168 |
else:
|
169 |
print("Error: Failed to synthesize audio. Status code:", response.status_code)
|
170 |
+
return None,None
|
171 |
|
172 |
|
173 |
|
|
|
277 |
|
278 |
##获取当前图片对应的临时音频文件名称和文案时长
|
279 |
filename, duration = get_audio_data(cur_copywrite)
|
280 |
+
if filename is not None:
|
281 |
+
print("存放临时mp3文件的路径是",filename)
|
282 |
+
clip = ImageClip(img).set_duration(duration).resize((width, height)) # 初始clip
|
283 |
+
|
284 |
+
txt_clip = TextClip(cur_copywrite, fontsize=40, color='white', bg_color='black',
|
285 |
+
font=font_path) ##文本clip后加入视频
|
286 |
+
|
287 |
+
txt_clip = txt_clip.set_pos(('center', 'bottom')).set_duration(duration)
|
288 |
+
# 创建音频剪辑
|
289 |
+
audio_clip = AudioFileClip(filename)
|
290 |
+
clip = clip.set_audio(audio_clip) # 将音频与视频片段关联
|
291 |
+
clip = CompositeVideoClip([clip, txt_clip])
|
292 |
+
video_clips.append(clip)
|
293 |
+
else:
|
294 |
+
pass ##音频特殊字符或者其他原因无法生成跳过
|
295 |
else:
|
296 |
pass ##图片不规范直接跳过
|
297 |
video = concatenate_videoclips(video_clips)
|