Exception using word_timestamps = True #2464
Replies: 3 comments 1 reply
-
This is the code I am using:
I am running python 3.12.8 on WIndows and here is the excepition : During handling of the above exception, another exception occurred: File "XXX\futur\src\YYY.py", line 652, in transcribe_video |
Beta Was this translation helpful? Give feedback.
-
Name: openai-whisper |
Beta Was this translation helpful? Give feedback.
-
Here is a simple example in order to reproduce: import whisper
from whisper.utils import get_writer
import torch
def transcribe_audio(audio_path, max_line_width=None, max_line_count=None):
# Load the Whisper model (using tiny.en on CPU)
model = whisper.load_model("tiny.en", device="cpu")
# Ensure we're using CPU for processing
torch.set_grad_enabled(False)
if torch.cuda.is_available():
torch.cuda.empty_cache()
# Transcribe the audio with specified parameters
result = model.transcribe(
audio_path,
language="en",
fp16=False, # Ensure we're not using fp16 on CPU
verbose=True,
word_timestamps=True
)
# Set up writer options
writer_options = {
"max_line_count": max_line_count,
"max_line_width": max_line_width
}
# Get SRT writer and write to current directory
output_directory = "./"
writer = get_writer("srt", output_directory)
# Write the result with specified formatting
writer(result, audio_path, writer_options)
return result["text"]
if __name__ == "__main__":
# Example usage
audio_file = r"C:\Users\fradae\Downloads\01_010 Workshop Introduction.mp4"
try:
# Example with both parameters
transcription = transcribe_audio(
audio_file,
max_line_width=32, # One word per line
max_line_count=3 # Maximum number of lines
)
print("\nTranscription has been saved as an SRT file in the current directory")
print("\nFull transcription text:")
print(transcription)
except Exception as e:
print(f"An error occurred during transcription: {str(e)}")
print("Full error details:", e.__class__.__name__) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When I use word_timestamps = True in transcribe function. An exception
'<code object dtw at 0x0000020163D5C200, file "\venv\Lib\site-packages\whisper\timing.py", line 141> != <code object dtw_cpu at 0x0000020161EC9C40, file "\venv\Lib\site-packages\whisper\timing.py", line 82>' is shown, how can I sovle this? I only use whisper.load_model("base",device="cpu") Thank you.
Beta Was this translation helpful? Give feedback.
All reactions