Whisper 中的结果格式化子系统负责将结构化的转录输出转换为适合不同用例的各种文件格式。此组件是转录管道的最后阶段,它接收带有时间戳的处理过的片段,并将它们转换为标准化格式,以便其他工具可以轻松使用或显示给用户。
有关整体转录过程的信息,请参阅 转录管道。
结果格式化系统围绕一个类层次结构构建,该结构具有处理不同输出格式的通用接口。
The ResultWriter class serves as the foundation for all format-specific writers. It defines a common interface for writing transcription results to files.
主要功能
__call__() thatwrite_result() methodwrite_result() method to be implemented by subclassesWhisper 支持以下输出格式
| 格式 | 类 | 扩展 | 描述 | 用例 |
|---|---|---|---|---|
| 文本 | WriteTXT | .txt | 纯文本转录 | 简单的可读性 |
| WebVTT | WriteVTT | .vtt | Web 视频文本轨道 | Web 视频字幕 |
| SRT | WriteSRT | .srt | SubRip 文本 | 视频播放器字幕 |
| TSV | WriteTSV | .tsv | 制表符分隔值 | 数据分析,电子表格 |
| JSON | WriteJSON | .json | JavaScript 对象表示法 | 程序化访问,API 响应 |
最简单的格式,仅输出片段的文本内容,每段占一行。
两种字幕格式均源自 SubtitlesWriter 抽象类,该类提供了通用功能
VTT 和 SRT 之间的主要区别
VTT:
00:01:23.456)WEBVTT 标题SRT:
00:01:23,456)输出开始时间、结束时间和文本的结构化格式,以制表符分隔的列
此格式对于在其他应用程序中解析或导入电子表格特别有用。
以 JSON 格式输出完整的转录结果,保留原始转录结果中的所有信息。
The system converts floating-point seconds into formatted timestamps through the format_timestamp() function
The iterate_result() method in SubtitlesWriter handles the complex logic of transforming segments into properly formatted subtitles
The get_writer() function creates the appropriate writer instance based on the requested output format
output_format and output_dir parameters"all" format that writes to all available formatsHere's how the result formatting system is typically used within the transcription pipeline
Common options for subtitle writers include
max_line_width: Maximum characters per linemax_line_count: Maximum lines per subtitlehighlight_words: Whether to highlight individual words in timestampsWhen word-level timestamps are available, subtitle writers can provide more granular timing information
The system includes safeguards for character encoding issues