Spaces:
Running
on
A10G
Running
on
A10G
Update audio.py
Browse files
audio.py
CHANGED
@@ -8,7 +8,7 @@ os.environ["IMAGEIO_FFMPEG_EXE"] = "/usr/local/bin/ffmpeg"
|
|
8 |
# 如果需要,设置 ImageMagick 的路径
|
9 |
# os.environ["IMAGEMAGICK_BINARY"] = "/usr/local/bin/convert"
|
10 |
|
11 |
-
def gen_audio(subtitles):
|
12 |
# 字幕列表,表示在指定时间段显示对应的字幕
|
13 |
# subtitles = [
|
14 |
# [[0, 3], "這裡請注意右臂"],
|
@@ -19,7 +19,7 @@ def gen_audio(subtitles):
|
|
19 |
print("===> Subtitles:")
|
20 |
for subtitle in subtitles:
|
21 |
print(subtitle)
|
22 |
-
combined_clip = VideoFileClip("
|
23 |
# 获取视频总时长
|
24 |
total_duration = combined_clip.duration
|
25 |
|
@@ -77,8 +77,8 @@ def gen_audio(subtitles):
|
|
77 |
video_with_audio = video_with_subtitles.set_audio(audio_clip)
|
78 |
|
79 |
# 导出带语音和字幕的视频
|
80 |
-
video_with_audio.write_videofile('
|
81 |
-
return '
|
82 |
|
83 |
|
84 |
def merge_subtitles(subtitles):
|
@@ -116,7 +116,7 @@ def merge_subtitles(subtitles):
|
|
116 |
break # 退出合并循环
|
117 |
|
118 |
# 添加合并后的字幕到新列表
|
119 |
-
current_content = '這裡請注意' + '、'.join(list(set(current_content.split('、'))))
|
120 |
merged_subtitles.append([[current_start, current_end], current_content])
|
121 |
|
122 |
return merged_subtitles
|
|
|
8 |
# 如果需要,设置 ImageMagick 的路径
|
9 |
# os.environ["IMAGEMAGICK_BINARY"] = "/usr/local/bin/convert"
|
10 |
|
11 |
+
def gen_audio(subtitles, tmpdir):
|
12 |
# 字幕列表,表示在指定时间段显示对应的字幕
|
13 |
# subtitles = [
|
14 |
# [[0, 3], "這裡請注意右臂"],
|
|
|
19 |
print("===> Subtitles:")
|
20 |
for subtitle in subtitles:
|
21 |
print(subtitle)
|
22 |
+
combined_clip = VideoFileClip(tmpdir + "/output.mp4")
|
23 |
# 获取视频总时长
|
24 |
total_duration = combined_clip.duration
|
25 |
|
|
|
77 |
video_with_audio = video_with_subtitles.set_audio(audio_clip)
|
78 |
|
79 |
# 导出带语音和字幕的视频
|
80 |
+
video_with_audio.write_videofile(tmpdir + '/output_with_subtitles.mp4', fps=24)
|
81 |
+
return tmpdir + '/output_with_subtitles.mp4'
|
82 |
|
83 |
|
84 |
def merge_subtitles(subtitles):
|
|
|
116 |
break # 退出合并循环
|
117 |
|
118 |
# 添加合并后的字幕到新列表
|
119 |
+
current_content = '這裡請注意' + '、'.join(list(set(current_content.replace("細節", "").split('、'))))
|
120 |
merged_subtitles.append([[current_start, current_end], current_content])
|
121 |
|
122 |
return merged_subtitles
|