gpt-4o-2024-05-13· OpenAI
WildChat-4.8M (AI2)
linux下,出来sed和awk,有什么工具可以把.srt格式转换成.txt?
- User
linux下,出来sed和awk,有什么工具可以把.srt格式转换成.txt?
- Assistant
在 Linux 下,除了
sed和awk,还有许多工具可以用于将.srt格式的字幕文件转换成普通的.txt文件。下面介绍几个常用的工具和如何使用它们:-
Python 脚本: 使用 Python 处理文本文件非常方便,可以编写简单的脚本来转换
.srt文件。以下是一个示例 Python 脚本:import re def srt_to_txt(srt_file, txt_file): with open(srt_file, 'r') as f: lines = f.readlines() with open(txt_file, 'w') as f: for line in lines: if re.match(r'^\d+$', line.strip()): continue # 跳过数字行 if re.match(r'^\d{2}:\d{2}:\d{2},\d{3} --> \d{2}:\d{2}:\d{2},\d{3}$', line.strip()): continue # 跳过时间戳行 if line.strip() == '': continue # 跳过空行 f.write(line) srt_to_txt('example.srt', 'output.txt')
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.