├── .gitignore ├── README.md ├── cache └── .gitignore ├── img ├── premiere_example.png └── terminal_example.png ├── log.py ├── main.py ├── premiere_convert.py ├── requirements.txt ├── start.bat ├── templates └── premiere_sequence.xml └── transcribe.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | 162 | # Custom 163 | test.py 164 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoCaptions 2 | 3 | **Transcribe an audio file to Premiere Pro layers** 4 | 5 | A GUI tool that uses [OpenAI's Whisper](https://github.com/openai/whisper) to transcribe text from an audio/video file, into a Premiere Pro sequence to automate the creation of subtitles. Mainly for adding quick subtitles to action-packed videos, by making segments of a small word count. 6 | 7 | Outputs a `.xml` file which is a sequence containing text layers (Essential Graphics) that can be imported into your Premiere Pro project. 8 | 9 | Uses [`stable-ts`](https://github.com/jianfch/stable-ts) regrouping functions to split the result into small configurable segments. 10 | 11 | ## Installation 12 | 13 | ```cmd 14 | git clone https://github.com/JorianWoltjer/AutoCaptions.git && cd AutoCaptions 15 | python -m pip install -r requirements.txt 16 | ``` 17 | 18 | ### Torch 19 | 20 | Make sure to install the GPU enabled version of `torch` to make Whisper a lot faster: 21 | 22 | ```shell 23 | python -m pip uninstall torch 24 | python -m pip cache purge 25 | python -m pip install torch -f https://download.pytorch.org/whl/torch_stable.html 26 | ``` 27 | 28 | ### ffmpeg 29 | 30 | An external dependency for Whisper that needs to be installed: 31 | 32 | ###### Windows 33 | 34 | Install [Chocolatey](https://docs.chocolatey.org/en-us/choco/setup), then run the following command: 35 | 36 | ```cmd 37 | choco install ffmpeg 38 | ``` 39 | 40 | ###### Linux 41 | 42 | ```Shell 43 | sudo apt update && sudo apt install ffmpeg 44 | ``` 45 | 46 | ## Running 47 | 48 | ###### Windows 49 | 50 | Simply create a shortcut to [`start.bat`](start.bat) 51 | 52 | ###### Linux 53 | 54 | ```shell 55 | $ python main.py 56 | ``` 57 | 58 | ## Example 59 | 60 | Start the batch script, and select a file as input. Then some configuration is available and you can transcribe the audio: 61 | 62 | ![A terminal showing Whisper output and some progress updates, with the simple GUI on Windows](img/terminal_example.png) 63 | 64 | The resulting XML file can then be imported into a Premiere project, where you can use and edit the text layers it created: 65 | 66 | ![A screenshot of the Premiere Pro timeline showing 3 text layers with the transcribed text](img/premiere_example.png) 67 | 68 | > **Tip**: To apply a style to all the text layers, you can create an Essential Graphics preset. Just do your settings on one of the layers, and then save it as a preset. Then you can drag the preset from your Project window to all the layers you select. 69 | > 70 | > For animation keyframes you want to save an Animation Preset, which you can do by right-clicking on your created effect with keyframes and saving the Preset. Then you can drag it from your Effects window under Presets to all the layers you select. 71 | 72 | ## Resources 73 | 74 | * https://github.com/jianfch/stable-ts 75 | * https://github.com/openai/whisper/discussions/3#discussioncomment-3730914 76 | -------------------------------------------------------------------------------- /cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /img/premiere_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/AutoCaptions/36452ae9aa88ed411502d8b7ec211733b285ecbd/img/premiere_example.png -------------------------------------------------------------------------------- /img/terminal_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JorianWoltjer/AutoCaptions/36452ae9aa88ed411502d8b7ec211733b285ecbd/img/terminal_example.png -------------------------------------------------------------------------------- /log.py: -------------------------------------------------------------------------------- 1 | from rich.console import Console 2 | 3 | console = Console() 4 | 5 | class log: 6 | def progress(*args, **kwargs): 7 | """Print an informational message prefixed with `[*]`""" 8 | console.print(r"\[[bright_blue]~[/bright_blue]]", *args, **kwargs) 9 | 10 | def success(*args, **kwargs): 11 | """Print a successful message prefixed with `[+]`""" 12 | console.print(r"\[[bright_green]+[/bright_green]]", *args, **kwargs) 13 | 14 | def warning(*args, **kwargs): 15 | """Print a warning message prefixed with `[!]`""" 16 | console.print(r"\[[bright_yellow]![/bright_yellow]]", *args, **kwargs) 17 | 18 | def error(*args, exit_after=True, **kwargs): 19 | """Prints an error message prefixed with `[!]`. **Exits** after printing (unless `exit_after=False`)""" 20 | console.print(r"\[[bright_red]![/bright_red]]", *args, **kwargs) 21 | if exit_after: exit() 22 | 23 | 24 | if __name__ == "__main__": 25 | log.progress("Some information.") 26 | log.success("Success! We did it!") 27 | log.warning("Be warned...") 28 | log.error("Oh no, an error!") 29 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import sys, os 2 | sys.path.append(os.path.dirname(os.path.realpath(__file__))) # Allow local imports from any working directory 3 | from log import console, log 4 | 5 | log.progress("Loading modules...") 6 | 7 | import tkinter 8 | from tkinter import ttk, ACTIVE, DISABLED, filedialog 9 | import sv_ttk 10 | from pathlib import Path 11 | import subprocess 12 | 13 | import premiere_convert 14 | from transcribe import transcribe_to_srt 15 | 16 | DIR = sys.path[0] 17 | 18 | def select_file(): 19 | filetypes = [ 20 | ("Audio Files", "*.wav;*.mp3;*.flac;*.aac;*.m4a"), 21 | ("Video Files", "*.mp4;*.mov;*.avi;*.mkv;*.wmv"), 22 | ('All files', '*.*') 23 | ] 24 | 25 | filename_ask = filedialog.askopenfilename( 26 | title='Select any Audio or Video file to be transcribed', 27 | filetypes=filetypes) 28 | 29 | if filename_ask == "": # if dialog closed with cancel 30 | return 31 | 32 | input_file_variable.set(filename_ask) 33 | feedback_variable.set("") 34 | start_button["state"] = ACTIVE 35 | start_button.focus() 36 | 37 | def file_save(): 38 | filetypes = ( 39 | ('Premiere Pro Sequence file', '*.xml'), 40 | ('All files', '*.*') 41 | ) 42 | 43 | path = Path(input_file_variable.get()) 44 | directory = path.parent 45 | filename = path.stem + ".xml" 46 | 47 | f = filedialog.asksaveasfile(mode='w', title="Save sequence file", filetypes=filetypes, initialdir=directory, initialfile=filename) 48 | if f is None: # if dialog closed with cancel 49 | return 50 | f.close() 51 | 52 | input_filepath = input_file_variable.get() 53 | 54 | start_button["state"] = DISABLED 55 | feedback_variable.set("Running... (see console for progress)") 56 | window.update() 57 | 58 | # Get configuration 59 | config_model = model_variable.get() 60 | config_split_gap = float(split_gap_variable.get()) 61 | config_split_length = int(split_length_variable.get()) 62 | 63 | # Transcribe audio using Whisper 64 | srt_filepath = transcribe_to_srt(input_filepath, 65 | model_name=config_model, 66 | split_gap=config_split_gap, 67 | split_length=config_split_length) 68 | 69 | # Convert SRT to Premiere XML text layers 70 | outfile = srt_to_xml(srt_filepath, f.name) 71 | 72 | # Open file in Explorer 73 | if sys.platform == "win32": 74 | open_file_in_explorer(f) 75 | 76 | feedback_variable.set("Done! Saved to " + outfile) 77 | input_file_variable.set("") 78 | 79 | # Convert SRT to Premiere Pro XML Sequence as Text Layers 80 | def srt_to_xml(srt_filename, outfile): 81 | with console.status(f"Converting {srt_filename} to Premiere Pro XML...", spinner="arc", spinner_style="blue"): 82 | premiere_xml = premiere_convert.srt_to_xml(srt_filename) 83 | 84 | # Write to file 85 | outfile = outfile + ".xml" if not outfile.endswith(".xml") else outfile 86 | 87 | with open(outfile, "w") as f: 88 | f.write(premiere_xml) 89 | 90 | log.success(f"Saved Premiere Pro XML to {outfile!r}") 91 | return outfile 92 | 93 | def open_file_in_explorer(f): 94 | filename = f.name.replace('/', '\\') 95 | subprocess.Popen(f'explorer /select,"{filename}"') 96 | 97 | 98 | window = tkinter.Tk() 99 | window.title('Transcribe Audio to Premiere Pro XML') 100 | 101 | frame = ttk.Frame(window) 102 | frame.pack() 103 | 104 | input_file_button = ttk.Button(frame, text="Select input file", command=select_file) 105 | input_file_button.grid(row=0, column=0, sticky="news", padx=20, pady=10) 106 | input_file_button.focus() 107 | input_file_variable = tkinter.StringVar(window) 108 | input_file_label = ttk.Label(frame, text="No file selected", textvariable=input_file_variable) 109 | input_file_label.grid(row=1, column=0, sticky="news", padx=20) 110 | 111 | config_frame = ttk.LabelFrame(frame, text="Configuration") 112 | config_frame.grid(row=2, column=0, padx=20, pady=10) 113 | 114 | model_label = ttk.Label(config_frame, text="Whisper Model") 115 | model_label.grid(row=0, column=0) 116 | model_variable = tkinter.StringVar(window) 117 | model_variable.set("small") 118 | model_combobox = ttk.Combobox(config_frame, values=["small", "medium", "large"], textvariable=model_variable) 119 | model_combobox.grid(row=1, column=0) 120 | 121 | split_gap_label = ttk.Label(config_frame, text="Split silence (s)") 122 | split_gap_label.grid(row=0, column=1) 123 | split_gap_variable = tkinter.StringVar(window) 124 | split_gap_variable.set("0.5") 125 | split_gap_spinbox = ttk.Spinbox(config_frame, from_=0, to=5, increment=0.1, textvariable=split_gap_variable) 126 | split_gap_spinbox.grid(row=1, column=1) 127 | 128 | split_length_label = ttk.Label(config_frame, text="Split length (chars)") 129 | split_length_label.grid(row=0, column=2) 130 | split_length_variable = tkinter.StringVar(window) 131 | split_length_variable.set("20") 132 | split_length_spinbox = ttk.Spinbox(config_frame, from_=0, to=100, increment=1, textvariable=split_length_variable) 133 | split_length_spinbox.grid(row=1, column=2) 134 | 135 | for widget in config_frame.winfo_children(): 136 | widget.grid_configure(padx=10, pady=10) 137 | 138 | feedback_variable = tkinter.StringVar(window) 139 | feedback_label = ttk.Label(frame, textvariable=feedback_variable) 140 | feedback_label.grid(row=3, column=0, sticky="news", padx=20) 141 | start_button = ttk.Button(frame, text="Transcribe to XML", command=file_save, state=DISABLED) 142 | start_button.grid(row=4, column=0, sticky="news", padx=20, pady=10) 143 | 144 | sv_ttk.set_theme("dark") 145 | 146 | log.progress("Starting GUI") 147 | window.mainloop() 148 | -------------------------------------------------------------------------------- /premiere_convert.py: -------------------------------------------------------------------------------- 1 | from jinja2 import Template 2 | from base64 import b64encode 3 | import json 4 | import pysrt 5 | import os 6 | import sys 7 | 8 | FRAME_RATE = 60 # FPS 9 | WIDTH, HEIGHT = 1920, 1080 10 | DIR = sys.path[0] 11 | 12 | with open(os.path.join(DIR, "templates", "premiere_sequence.xml")) as f: 13 | template = Template(f.read()) 14 | 15 | def total_secs(time): 16 | secs = time.milliseconds / 1000 17 | secs += time.seconds 18 | secs += time.minutes * 60 19 | secs += time.hours * 60 * 60 20 | return secs 21 | 22 | def make_data(text): 23 | data = {"mShadowFontMapHash": None, 24 | "mTextParam": { 25 | "mAlignment": 2.0, 26 | "mBackFillColor": 0.0, 27 | "mBackFillOpacity": 0.0, 28 | "mBackFillSize": 0.0, 29 | "mBackFillVisible": False, 30 | "mDefaultRun": [], 31 | "mHeight": 0.0, 32 | "mHindiDigits": False, 33 | "mIndic": False, 34 | "mIsMask": False, 35 | "mIsMaskInverted": False, 36 | "mIsVerticalText": False, 37 | "mLeading": 0.0, 38 | "mLigatures": False, 39 | "mLineCapType": 0.0, 40 | "mLineJoinType": 0.0, 41 | "mMiterLimit": 0.0, 42 | "mNumStrokes": 1.0, 43 | "mRTL": False, 44 | "mShadowAngle": 135.0, 45 | "mShadowBlur": 40.0, 46 | "mShadowColor": 4144959.0, 47 | "mShadowOffset": 7.0, 48 | "mShadowOpacity": 75.0, 49 | "mShadowSize": 0.0, 50 | "mShadowVisible": False, 51 | "mStyleSheet": { 52 | "mAdditionalStrokeColor": [], 53 | "mAdditionalStrokeVisible": [], 54 | "mAdditionalStrokeWidth": [], 55 | "mBaselineOption": {"mParamValues": [[0.0, 0.0]]}, 56 | "mBaselineShift": {"mParamValues": [[0.0, 0.0]]}, 57 | "mCapsOption": {"mParamValues": [[0.0, 0.0]]}, 58 | "mFauxBold": {"mParamValues": [[0, False]]}, 59 | "mFauxItalic": {"mParamValues": [[0, False]]}, 60 | "mFillColor": {"mParamValues": [[0.0, 16777215.0]]}, 61 | "mFillOverStroke": {"mParamValues": [[0, True]]}, 62 | "mFillVisible": {"mParamValues": [[0, True]]}, 63 | "mFontName": {"mParamValues": [[0, "ArialMT"]]}, 64 | "mFontSize": {"mParamValues": [[0.0, 60.0]]}, 65 | "mKerning": {"mParamValues": [[0.0, 0.0]]}, 66 | "mStrokeColor": {"mParamValues": [[0.0, 0.0]]}, 67 | "mStrokeVisible": {"mParamValues": [[0, True]]}, 68 | "mStrokeWidth": {"mParamValues": [[0.0, 10.0]]}, 69 | "mText": text, 70 | "mTracking": {"mParamValues": [[0.0, 0.0]]}, 71 | "mTsumi": {"mParamValues": [[0.0, 0.0]]}, 72 | "mUnderline": None}, 73 | "mTabWidth": 400.0, 74 | "mVerticalAlignment": 0.0, 75 | "mWidth": 0.0}, 76 | "mUseLegacyTextBox": False, 77 | "mVersion": 1.0 78 | } 79 | 80 | s = json.dumps(data, ensure_ascii=False) # Makes sure characters like 'é' are not escaped 81 | 82 | data = b"\x0f\x0f\x00\x00\x00\x00\x00\x00" + s.encode('utf-16-le') 83 | 84 | return b64encode(data).decode('utf-8') 85 | 86 | def ascii(text): 87 | import unicodedata 88 | return unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('utf-8') 89 | 90 | def srt_to_xml(srt_filename): 91 | clips = [] 92 | 93 | captions = pysrt.open(srt_filename) 94 | for line in captions: 95 | clips.append({ 96 | "name": ascii(line.text), # Convert to ascii 97 | "start": round(total_secs(line.start)*FRAME_RATE), 98 | "end": round(total_secs(line.end)*FRAME_RATE), 99 | "data": make_data(line.text.rstrip('.')) 100 | }) 101 | 102 | settings = { 103 | "duration": clips[-1]['end'], 104 | "timebase": FRAME_RATE, 105 | "width": WIDTH, 106 | "height": HEIGHT 107 | } 108 | 109 | filename = os.path.splitext(os.path.basename(srt_filename))[0] 110 | 111 | return template.render(settings=settings, clips=clips, filename=filename) 112 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | rich 2 | Jinja2 3 | pysrt 4 | sv-ttk 5 | 6 | setuptools-rust 7 | openai-whisper 8 | git+https://github.com/jianfch/stable-ts.git 9 | faster-whisper -------------------------------------------------------------------------------- /start.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | python main.py 3 | pause -------------------------------------------------------------------------------- /templates/premiere_sequence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{ settings.duration }} 6 | 7 | {{ settings.timebase }} 8 | false 9 | 10 | Captions ({{ filename }}) 11 | 12 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /transcribe.py: -------------------------------------------------------------------------------- 1 | from hashlib import md5 2 | import os, sys 3 | import torch, gc 4 | import json 5 | from stable_whisper import load_faster_whisper, WhisperResult 6 | from log import log, console 7 | 8 | DIR = sys.path[0] 9 | 10 | def unique_filename(filepath, model_name): 11 | hash = md5(open(filepath, 'rb').read()).hexdigest() 12 | path = os.path.join(DIR, 'cache', f"{hash}-{model_name}.json") 13 | return path 14 | 15 | def get_cache(filepath, model_name) -> WhisperResult: 16 | """Check if the Whisper output is cached, and if so, return it.""" 17 | filepath = unique_filename(filepath, model_name) 18 | if os.path.exists(filepath): 19 | with open(filepath, 'r') as f: 20 | return WhisperResult(json.load(f)) 21 | 22 | def put_cache(filepath, model_name, results: WhisperResult): 23 | """Cache the Whisper output.""" 24 | os.makedirs(os.path.join(DIR, 'cache'), exist_ok=True) 25 | filepath = unique_filename(filepath, model_name) 26 | with open(filepath, 'w') as f: 27 | json.dump(results.to_dict(), f) 28 | 29 | # Convert audio to SRT using Whisper 30 | def transcribe_to_srt(filepath, model_name='small', split_gap=0.5, split_length=20): 31 | cached = get_cache(filepath, model_name) 32 | if cached: 33 | result = cached 34 | log.success("Loaded [green]CACHED[/green] Whisper results!") 35 | else: 36 | # Load model 37 | log.progress(f"Loading Whisper {model_name!r} model...") 38 | model = load_faster_whisper(model_name) 39 | log.success("Loaded Whisper model") 40 | # Start transcribing 41 | log.progress(f"Transcribing using Whisper (this may take some time)...") 42 | # result: WhisperResult = model.transcribe(filepath, regroup=False) 43 | result: WhisperResult = model.transcribe_stable(filepath, regroup=False) 44 | 45 | put_cache(filepath, model_name, result) 46 | log.success("Completed Whisper (and saved to cache)") 47 | 48 | # Convert format and combine words 49 | with console.status(f"Regrouping words...", spinner="arc", spinner_style="blue"): 50 | ( # Thanks stable-ts for a better implementation of what I did myself :) 51 | result 52 | .clamp_max() 53 | .split_by_punctuation([('.', ' '), '。', '?', '?', (',', ' '), ',']) # Use nice split places 54 | .split_by_gap(split_gap) # Split gaps of >0.3 seconds 55 | .split_by_length(split_length) # Max length of 20 characters 56 | .split_by_punctuation([('.', ' '), '。', '?', '?']) # Force split by punctuation 57 | ) 58 | 59 | srt_filepath = filepath + '.srt' 60 | result.to_srt_vtt(srt_filepath, word_level=False) 61 | # TODO: In the future maybe add word-level animation? 62 | 63 | # Print results 64 | for seg in result.to_dict()['segments']: 65 | print(f"[{seg['start']:0.2f} - {seg['end']:0.2f}] {seg['text'].strip()}") 66 | 67 | log.success(f"Succesfully transcribed audio!") 68 | 69 | # Prevent memory leak 70 | if not cached: 71 | del model 72 | gc.collect() 73 | torch.cuda.empty_cache() 74 | if torch.cuda.memory_allocated() > 0: 75 | log.warning("[yellow]WARNING[/yellow]: Memory was not fully cleared. This is a bug! Please report it with some information about your system.") 76 | 77 | return srt_filepath 78 | --------------------------------------------------------------------------------