whisper
whisper copied to clipboard
Add subtitle format and font color in word_options dict
Refactored iterate_result function to include a new subtitle_format option that modifies the style of subtitles. The function now iterates through the subtitles and formats the subtitle text based on the subtitle_format option. If the option is not provided, the default value of None is used. The value None will produce at most a warning when reading it from third part software (like FFMPEG) since there will be an empty HTML tag inside <None>
.
Also a font_color
option allow to insert an hex color in format #FFFFFF (white) to change the font color while producing the .srt file. If not specified, it uses the default white color.
The iterate_result
function in utils.py
now includes a new subtitle_format
option that modifies the style of subtitles. The available options are:
-
"u"
: Subtitles are underlined. -
"b"
: Subtitles are bolded. -
"i"
: Subtitles are italicized.
To use this option, simply include "subtitle_format": "u"
, "subtitle_format": "b"
, or "subtitle_format": "i"
in the word_options
dictionary.
Example of usage:
import whisper
from whisper.utils import get_writer
audio = './audio.mp3'
model = whisper.load_model(model='small')
result = model.transcribe(audio=audio, language='en', word_timestamps=True, task="transcribe")
# Set VTT Line and words width
word_options = {
"highlight_words": False,
"max_line_count": 1,
"max_line_width": 42,
"subtitle_format": "b", # bold word highlighting
"font_color": "#fff000", # yellow font color
}
vtt_writer = get_writer(output_format='vtt', output_dir='./')
vtt_writer(result, audio, word_options)