mirror of
https://github.com/m-bain/whisperX.git
synced 2025-07-01 18:17:27 -04:00
fallback on whisper alignment failures, update readme
This commit is contained in:
16
README.md
16
README.md
@ -23,7 +23,6 @@
|
||||
<a href="#setup">Setup</a> •
|
||||
<a href="#example">Usage</a> •
|
||||
<a href="#other-languages">Multilingual</a> •
|
||||
<a href="#python-usage">Python</a> •
|
||||
<a href="#contribute">Contribute</a> •
|
||||
<a href="EXAMPLES.md">More examples</a>
|
||||
</p>
|
||||
@ -33,7 +32,6 @@
|
||||
<img width="1216" align="center" alt="whisperx-arch" src="https://user-images.githubusercontent.com/36994049/208313881-903ab3ea-4932-45fd-b3dc-70876cddaaa2.png">
|
||||
|
||||
|
||||
|
||||
<p align="left">Whisper-Based Automatic Speech Recognition (ASR) with improved timestamp accuracy using forced alignment.
|
||||
|
||||
</p>
|
||||
@ -55,6 +53,20 @@ Install this package using
|
||||
|
||||
`pip install git+https://github.com/m-bain/whisperx.git`
|
||||
|
||||
If already installed, update package to most recent commit
|
||||
|
||||
`pip install git+https://github.com/m-bain/whisperx.git --upgrade`
|
||||
|
||||
If wishing to modify this package, clone and install in editable mode:
|
||||
```
|
||||
$ git clone https://github.com/m-bain/whisperX.git
|
||||
$ cd whisperX
|
||||
$ pip install -e .
|
||||
```
|
||||
|
||||
|
||||
`pip install git+https://github.com/m-bain/whisperx.git --upgrade`
|
||||
|
||||
You may also need to install ffmpeg, rust etc. Follow openAI instructions here https://github.com/openai/whisper#setup.
|
||||
|
||||
<h2 align="left" id="example">Usage 💬 (command line)</h2>
|
||||
|
@ -2,6 +2,7 @@ numpy
|
||||
torch
|
||||
torchaudio
|
||||
tqdm
|
||||
soundfile
|
||||
more-itertools
|
||||
transformers>=4.19.0
|
||||
ffmpeg-python==0.2.0
|
||||
|
@ -64,7 +64,8 @@ def backtrack(trellis, emission, tokens, blank_id=0):
|
||||
if j == 0:
|
||||
break
|
||||
else:
|
||||
raise ValueError("Failed to align")
|
||||
# failed
|
||||
return None
|
||||
return path[::-1]
|
||||
|
||||
# Merge the labels
|
||||
|
@ -293,7 +293,11 @@ def align(
|
||||
word_segments_list = []
|
||||
for idx, segment in enumerate(transcript):
|
||||
if int(segment['start'] * SAMPLE_RATE) >= audio.shape[1]:
|
||||
# original whisper error, transcript is outside of duration of audio, not possible. Skip to next (finish).
|
||||
print("Failed to align segment: original start time longer than audio duration, skipping...")
|
||||
continue
|
||||
|
||||
if int(segment['start']) >= int(segment['end']):
|
||||
print("Failed to align segment: original end time is not after start time, skipping...")
|
||||
continue
|
||||
|
||||
t1 = max(segment['start'] - extend_duration, 0)
|
||||
@ -325,11 +329,16 @@ def align(
|
||||
t_words_nonempty_idx = [x for x in range(len(t_words_clean)) if t_words_clean[x] != ""]
|
||||
segment['word-level'] = []
|
||||
|
||||
fail_fallback = False
|
||||
if len(t_words_nonempty) > 0:
|
||||
transcription_cleaned = "|".join(t_words_nonempty).lower()
|
||||
tokens = [model_dictionary[c] for c in transcription_cleaned]
|
||||
trellis = get_trellis(emission, tokens)
|
||||
path = backtrack(trellis, emission, tokens)
|
||||
if path is None:
|
||||
print("Failed to align segment: backtrack failed, resorting to original...")
|
||||
fail_fallback = True
|
||||
else:
|
||||
segments = merge_repeats(path, transcription_cleaned)
|
||||
word_segments = merge_words(segments)
|
||||
ratio = waveform_segment.size(0) / (trellis.size(0) - 1)
|
||||
@ -372,6 +381,9 @@ def align(
|
||||
else:
|
||||
word_segments_list[-1]['text'] += ' ' + curr_word
|
||||
else:
|
||||
fail_fallback = True
|
||||
|
||||
if fail_fallback:
|
||||
# then we resort back to original whisper timestamps
|
||||
# segment['start] and segment['end'] are unchanged
|
||||
prev_t2 = 0
|
||||
|
Reference in New Issue
Block a user