import os import whisper from whisper.utils import get_writer # Get the current directory path directory = os.getcwd() # Loop through all the files in the directory for file in sorted(os.listdir(directory)): # Check if the file has the mp4 extension if file.endswith('.mp4'): # Get the name of the file with the extension name = os.path.splitext(file)[0] + '.mp4' srt_file = directory + '/' + name + '.srt' # Check if there is a related srt file if not os.path.isfile(srt_file): # Create srt for all mp4 files that need one print('Processing ' + file + '...') model = whisper.load_model('large') result = model.transcribe(file, fp16=False) srt_writer = get_writer('srt', './') srt_writer(result, file)