Transcribe and return raw text
faster-whisper returns transcription as an iterator of segments, not a single string. Each segment has a start time, end time, and text. The simplest output is the concatenated text of every segment, but you can also keep timestamps for captioning or search.
def transcribe(self, audio_file):
print('Transcribing...')
segments, info = self.whisper.transcribe(
audio_file,
beam_size=5,
language='en',
condition_on_previous_text=False,
)
text = ' '.join([segment.text for segment in segments]).strip()
print(f'Raw: {text}')
return textbeam_size=5 trades a little speed for better accuracy. condition_on_previous_text=False stops the model from reusing earlier context, which prevents hallucination loops on silent audio.
Beam search keeps the top N candidate transcriptions at each step and picks the best sequence overall. beam_size=1 is greedy decoding, fast but lower quality. beam_size=5 is a common sweet spot, costing a bit more compute for a noticeable accuracy bump.
Quiz: Quiz
Loading practice…
Checkpoint: Local Whisper checkpoint
Loading practice…