|
发表于 2024-4-15 07:37:25
|
显示全部楼层
以下是给跨行字幕加标点的代码:
import re
# 输入跨行字幕
subtitles = """
1
00:00:00,200 --> 00:00:00,839
2
00:00:00,840 --> 00:00:02,999
it was another beautiful Winter's
3
00:00:03,000 --> 00:00:07,239
morning and all was quiet in the
4
00:00:07,240 --> 00:00:10,758
meadow except perhaps for a playful
5
00:00:10,759 --> 00:00:13,239
little nut brown hair and his
6
00:00:13,240 --> 00:00:15,758
father I know where you are little nut
7
00:00:15,759 --> 00:00:19,358
brown hair because I can hear
8
00:00:19,359 --> 00:00:23,499
you and I've got a very squishy squashy
9
00:00:23,500 --> 00:00:25,919
10
00:00:25,920 --> 00:00:32,370
snowball I'm going to get you now
11
00:00:32,380 --> 00:00:35,709
12
00:00:35,719 --> 00:00:39,999
I got you big nut brown hair oh you did
13
00:00:40,000 --> 00:00:43,470
but now it's my
14
00:00:43,480 --> 00:00:51,990
turn miss
15
00:00:52,000 --> 00:00:58,910
me you won't get
16
00:00:58,920 --> 00:01:00,558
far
17
00:01:00,559 --> 00:01:04,839
oh you're funny big nut brown
18
00:01:04,840 --> 00:01:08,279
hair just you wait I have an even better
19
00:01:08,280 --> 00:01:11,989
snowball now you'll have to catch me
20
00:01:11,990 --> 00:01:13,619
21
00:01:13,620 --> 00:01:22,798
22
00:01:22,799 --> 00:01:25,919
first hello
23
00:01:25,920 --> 00:01:28,839
24
00:01:28,840 --> 00:01:30,639
little
25
00:01:30,640 --> 00:01:33,398
I'm sorry little field mouse that's all
26
00:01:33,399 --> 00:01:36,118
right little nut brown hair it was
27
00:01:36,119 --> 00:01:37,599
pretty
28
00:01:37,600 --> 00:01:39,909
funny it sure
29
00:01:39,910 --> 00:01:43,438
30
00:01:43,439 --> 00:01:49,310
was oh let's go and see who that
31
00:01:49,320 --> 00:01:54,438
is wow W hello little gray squirrel
32
00:01:54,439 --> 00:01:59,438
hello otter hello what are you doing wo
33
00:01:59,439 --> 00:02:02,758
such a a beautiful sunny day I thought I
34
00:02:02,759 --> 00:02:07,398
would get out of my tree and go
35
00:02:07,399 --> 00:02:11,369
skating it's fun you should try
36
00:02:11,370 --> 00:02:16,229
37
00:02:16,239 --> 00:02:20,238
it how do you do it well I just take a
38
00:02:20,239 --> 00:02:24,399
step then I wiggle my tail on the ice
39
00:02:24,400 --> 00:02:26,318
and then I'm
40
00:02:26,319 --> 00:02:30,839
skating or you can slide on your tummy
41
00:02:30,840 --> 00:02:33,229
like
42
00:02:33,239 --> 00:02:36,279
me there are lots and lots of different
43
00:02:36,280 --> 00:02:37,999
ways to
44
00:02:38,000 --> 00:02:40,749
skate shall
45
00:02:40,750 --> 00:02:50,958
46
00:02:50,959 --> 00:02:54,999
we yes this is
47
00:02:55,000 --> 00:02:58,799
fun come on little that brown hair all
48
00:02:58,800 --> 00:03:00,769
right then watch
49
00:03:00,770 --> 00:03:10,390
50
00:03:10,400 --> 00:03:17,589
me wo
51
00:03:17,599 --> 00:03:21,878
wo you're funny little nut brown hair
52
00:03:21,879 --> 00:03:24,999
ah yes
53
00:03:25,000 --> 00:03:29,318
funny but I think I hear um Big N brown
54
00:03:29,319 --> 00:03:31,598
heck calling
55
00:03:31,599 --> 00:03:38,910
me I didn't hear anything me
56
00:03:38,920 --> 00:03:43,639
either and then they laughed at
57
00:03:43,640 --> 00:03:46,798
me oh I'm sure they weren't being mean
58
00:03:46,799 --> 00:03:49,598
little nut brown hair you laughed at me
59
00:03:49,599 --> 00:03:52,199
when I fell over but you weren't being
60
00:03:52,200 --> 00:03:56,999
mean but what if I fall over
61
00:03:57,000 --> 00:04:00,078
again I fell over a lot when when I
62
00:04:00,079 --> 00:04:02,318
first started skating but after I
63
00:04:02,319 --> 00:04:04,598
practiced for a while I got better I
64
00:04:04,599 --> 00:04:07,559
could help you if you like would you
65
00:04:07,560 --> 00:04:10,279
really of course I would little nut
66
00:04:10,280 --> 00:04:12,639
brown hair but we might wait until the
67
00:04:12,640 --> 00:04:16,990
others have gone home
68
00:04:17,000 --> 00:04:21,319
H it takes some of us like you and me a
69
00:04:21,320 --> 00:04:23,319
bit longer than others to learn how to
70
00:04:23,320 --> 00:04:27,319
skate but that's all right it is sure
71
00:04:27,320 --> 00:04:29,719
everybody's different and we get there
72
00:04:29,720 --> 00:04:33,870
with a bit of
73
00:04:33,880 --> 00:04:36,399
practice come
74
00:04:36,400 --> 00:04:40,198
on oh it's
75
00:04:40,199 --> 00:04:44,439
okay okay carefully
76
00:04:44,440 --> 00:04:47,839
now just take little steps until you get
77
00:04:47,840 --> 00:04:52,079
a feel for the ice yes little field
78
00:04:52,080 --> 00:04:56,510
mouse took Little
79
00:04:56,520 --> 00:04:58,559
80
00:04:58,560 --> 00:05:02,279
Steps it's all right I've got you I've
81
00:05:02,280 --> 00:05:07,230
got
82
00:05:07,240 --> 00:05:10,638
you take big breaths
83
00:05:10,639 --> 00:05:14,150
in and
84
00:05:14,160 --> 00:05:16,279
out
85
00:05:16,280 --> 00:05:18,719
in
86
00:05:18,720 --> 00:05:20,839
out
87
00:05:20,840 --> 00:05:22,129
in
88
00:05:22,130 --> 00:05:24,638
89
00:05:24,639 --> 00:05:30,719
out that's it now let's Glide
90
00:05:30,720 --> 00:05:32,918
a this is
91
00:05:32,919 --> 00:05:36,079
skating this is
92
00:05:36,080 --> 00:05:40,999
skating that's it yes
93
00:05:41,000 --> 00:05:46,359
mhm do you want to try it on your own I
94
00:05:46,360 --> 00:05:50,679
I think so just remember little steps
95
00:05:50,680 --> 00:05:52,758
and big
96
00:05:52,759 --> 00:05:58,469
breaths little steps and big
97
00:05:58,479 --> 00:06:01,590
breaths
98
00:06:01,600 --> 00:06:04,529
I'm standing I'm
99
00:06:04,530 --> 00:06:11,870
100
00:06:11,880 --> 00:06:15,758
standing we were both funny that
101
00:06:15,759 --> 00:06:18,318
time yes we
102
00:06:18,319 --> 00:06:22,478
were are you okay yes I did a lot better
103
00:06:22,479 --> 00:06:25,758
than the first time I stood on ice and I
104
00:06:25,759 --> 00:06:28,399
bet you'll do even better this
105
00:06:28,400 --> 00:06:30,638
time
106
00:06:30,639 --> 00:06:39,870
oh Little Steps Little
107
00:06:39,880 --> 00:06:43,758
Steps I'm skating I'm
108
00:06:43,759 --> 00:06:46,918
skating you are little nut brown hair
109
00:06:46,919 --> 00:06:48,849
you certainly
110
00:06:48,850 --> 00:06:56,629
111
00:06:56,639 --> 00:06:59,959
are good morning skaters
"""
# 使用正则表达式将时间轴与文本内容分离
lines = re.split(r'\n\d+\n', subtitles)
# 添加标点符号
punctuation = ['.', ',', '!', '?']
final_subtitles = ''
for i, line in enumerate(lines):
line = line.strip()
if line:
if line.isdigit():
final_subtitles += line + '\n\n'
else:
if line[-1] not in punctuation:
final_subtitles += line + '.' + '\n\n'
else:
final_subtitles += line + '\n\n'
print(final_subtitles)
输出结果:
1
00:00:00,200 --> 00:00:00,839
2
00:00:00,840 --> 00:00:02,999
it was another beautiful Winter's.
3
00:00:03,000 --> 00:00:07,239
morning and all was quiet in the.
4
00:00:07,240 --> 00:00:10,758
meadow except perhaps for a playful.
5
00:00:10,759 --> 00:00:13,239
little nut brown hair and his.
6
00:00:13,240 --> 00:00:15,758
father I know where you are little nut.
7
00:00:15,759 --> 00:00:19,358
brown hair because I can hear.
8
00:00:19,359 --> 00:00:23,499
you and I've got a very squishy squashy.
9
00:00:23,500 --> 00:00:25,919
10
00:00:25,920 --> 00:00:32,370
snowball I'm going to get you now.
11
00:00:32,380 --> 00:00:35,709
12
00:00:35,719 --> 00:00:39,999
I got you big nut brown hair oh you did.
13
00:00:40,000 --> 00:00:43,470
but now it's my.
14
00:00:43,480 --> 00:00:51,990
turn miss.
15
00:00:52,000 --> 00:00:58,910
me you won't get.
16
00:00:58,920 --> 00:01:00,558
far.
17
00:01:00,559 --> 00:01:04,839
oh you're funny big nut brown.
18
00:01:04,840 --> 00:01:08,279
hair just you wait I have an even better.
19
00:01:08,280 --> 00:01:11,989
snowball now you'll have to catch me.
20
00:01:11,990 --> 00:01:13,619
21
00:01:13,620 --> 00:01:22,798
22
00:01:22,799 --> 00:01:25,919
first hello.
23
00:01:25,920 --> 00:01:28,839
24
00:01:28,840 --> 00:01:30,639
little.
25
00:01:30,640 --> 00:01:33,398
I'm sorry little field mouse that's all.
26
00:01:33,399 --> 00:01:36,118
right little nut brown hair it was.
27
00:01:36,119 --> 00:01:37,599
pretty.
28
00:01:37,600 --> 00:01:39,909
funny it sure.
29
00:01:39,910 --> 00:01:43,438
30
00:01:43,439 --> 00:01:49,310
was oh let's go and see who that.
31
00:01:49,320 --> 00:01:54,438
is wow W hello little gray squirrel.
32
00:01:54,439 --> 00:01:59,438
hello otter hello what are you doing wo.
33
00:01:59,439 --> 00:02:02,758
such a a beautiful sunny day I thought I.
34
00:02:02,759 --> 00:02:07,398
would get out of my tree and go.
35
00:02:07,399 --> 00:02:11,369
skating it's fun you should try.
36
00:02:11,370 --> 00:02:16,229
37
00:02:16,239 --> 00:02:20,238
it how do you do it well I just take a.
38
00:02:20,239 --> 00:02:24,399
step then I wiggle my tail on the ice.
39
00:02:24,400 --> 00:02:26,318
and then I'm.
40
00:02:26,319 --> 00:02:30,839
skating or you can slide on your tummy.
41
00:02:30,840 --> 00:02:33,229
like.
42
00:02:33,239 --> 00:02:36,279
me there are lots and lots of different.
43
00:02:36,280 --> 00:02:37,999
ways to.
44
00:02:38,000 --> 00:02:40,749
skate shall.
45
00:02:40,750 --> 00:02:50,958
46
00:02:50,959 --> 00:02:54,999
we yes this is.
47
00:02:55,000 --> 00:02:58,799
fun come on little that brown hair all.
48
00:02:58,800 --> 00:03:00,769
right then watch.
49
00:03:00,770 --> 00:03:10,390
50
00:03:10,400 --> 00:03:17,589
me wo.
51
00:03:17,599 --> 00:03:21,878
wo you're funny little nut brown hair.
52
00:03:21,879 --> 00:03:24,999
ah yes.
53
00:03:25,000 --> 00:03:29,318
funny but I think I hear um Big N brown.
54
00:03:29,319 --> 00:03:31,598
heck calling.
55
00:03:31,599 --> 00:03:38,910
me I didn't hear anything me.
56
00:03:38,920 --> 00:03:43,639
either and then they laughed at.
57
00:03:43,640 --> 00:03:46,798
me oh I'm sure they weren't being mean.
58
00:03:46,799 --> 00:03:49,598
little nut brown hair you laughed at me.
59
00:03:49,599 --> 00:03:52,199
when I fell over but you weren't being.
60
00:03:52,200 --> 00:03:56,999
mean but what if I fall over.
61
00:03:57,000 --> 00:04:00,078
again I fell over a lot when when I.
62
00:04:00,079 --> 00:04:02,318
first started skating but after I.
63
00:04:02,319 --> 00:04:04,598
practiced for a while I got better I.
64
00:04:04,599 --> 00:04:07,559
could help you if you like would you.
65
00:04:07,560 --> 00:04:10,279
really of course I would little nut.
66
00:04:10,280 --> 00:04:12,639
brown hair but we might wait until the.
67
00:04:12,640 --> 00:04:16,990
others have gone home.
68
00:04:17,000 --> 00:04:21,319
H it takes some of us like you and me a.
69
00:04:21,320 --> 00:04:23,319
bit longer than others to learn how to.
70
00:04:23,320 --> 00:04:27,319
skate but that's all right it is sure.
71
00:04:27,320 --> 00:04:29,719
everybody's different and we get there.
72
00:04:29,720 --> 00:04:33,870
with a bit of.
73
00:04:33,880 --> 00:04:36,399
practice come.
74
00:04:36,400 --> 00:04:40,198
on oh it's.
75
00:04:40,199 --> 00:04:44,439
okay okay carefully.
76
00:04:44,440 --> 00:04:47,839
now just take little steps until you get.
77
00:04:47,840 --> 00:04:52,079
a feel for the ice yes little field.
78
00:04:52,080 --> 00:04:56,510
mouse took Little.
79
00:04:56,520 --> 00:04:58,559
80
00:04:58,560 --> 00:05:02,279
Steps it's all right I've got you I've.
81
00:05:02,280 --> 00:05:07,230
got.
82
00:05:07,240 --> 00:05:10,638
you take big breaths.
83
00:05:10,639 --> 00:05:14,150
in and.
84
00:05:14,160 --> 00:05:16,279
out.
85
00:05:16,280 --> 00:05:18,719
in.
86
00:05:18,720 --> 00:05:20,839
out.
87
00:05:20,840 --> 00:05:22,129
in.
88
00:05:22,130 --> 00:05:24,638
89
00:05:24,639 --> 00:05:30,719
out that's it now let's Glide.
90
00:05:30,720 --> 00:05:32,918
a this is.
91
00:05:32,919 --> 00:05:36,079
skating this is.
92
00:05:36,080 --> 00:05:40,999
skating that's it yes.
93
00:05:41,000 --> 00:05:46,359
mhm do you want to try it on your own I.
94
00:05:46,360 --> 00:05:50,679
I think so just remember little steps.
95
00:05:50,680 --> 00:05:52,758
and big.
96
00:05:52,759 --> 00:05:58,469
breaths little steps and big.
97
00:05:58,479 --> 00:06:01,590
breaths.
98
00:06:01,600 --> 00:06:04,529
I'm standing I'm.
99
00:06:04,530 --> 00:06:11,870
100
00:06:11,880 --> 00:06:15,758
standing we were both funny that.
101
00:06:15,759 --> 00:06:18,318
time yes we.
102
00:06:18,319 --> 00:06:22,478
were are you okay yes I did a lot better.
103
00:06:22,479 --> 00:06:25,758
than the first time I stood on ice and I.
104
00:06:25,759 --> 00:06:28,399
bet you'll do even better this.
105
00:06:28,400 --> 00:06:30,638
time.
106
00:06:30,639 --> 00:06:39,870
oh Little Steps Little.
107
00:06:39,880 --> 00:06:43,758
Steps I'm skating I'm.
108
00:06:43,759 --> 00:06:46,918
skating you are little nut brown hair.
109
00:06:46,919 --> 00:06:48,849
you certainly.
110
00:06:48,850 --> 00:06:56,629
111
00:06:56,639 --> 00:06:59,959
are good morning skaters.
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|