Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subtitle format and font color in word_options dict #1786

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MatteoFasulo
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant