Skip to content

Commit

Permalink
Merge branch 'guillaumekln:master' into return-best-result
Browse files Browse the repository at this point in the history
  • Loading branch information
hoonlight authored Jul 19, 2023
2 parents 0e58b3f + 687db31 commit c9e07ab
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ Models can also be converted from the code. See the [conversion API](https://ope

1. Directly load the model from a local directory:
```python
model = faster_whisper.WhisperModel('whisper-large-v2-ct2')
model = faster_whisper.WhisperModel("whisper-large-v2-ct2")
```

2. [Upload your model to the Hugging Face Hub](https://huggingface.co/docs/transformers/model_sharing#upload-with-the-web-interface) and load it from its name:
```python
model = faster_whisper.WhisperModel('username/whisper-large-v2-ct2')
model = faster_whisper.WhisperModel("username/whisper-large-v2-ct2")
```

## Comparing performance against other implementations
Expand Down
4 changes: 2 additions & 2 deletions faster_whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ def get_prompt(
prefix_tokens = tokenizer.encode(" " + prefix.strip())
if len(prefix_tokens) >= self.max_length // 2:
prefix_tokens = prefix_tokens[: self.max_length // 2 - 1]
if not without_timestamps:
prompt.append(tokenizer.timestamp_begin)
prompt.extend(prefix_tokens)

return prompt
Expand Down Expand Up @@ -733,8 +735,6 @@ def add_word_timestamps(
# hack: truncate long words at sentence boundaries.
# a better segmentation algorithm based on VAD should be able to replace this.
if len(word_durations) > 0:
median_duration = np.median(word_durations)
max_duration = median_duration * 2
sentence_end_marks = ".。!!??"
# ensure words at sentence boundaries
# are not longer than twice the median word duration.
Expand Down
2 changes: 1 addition & 1 deletion faster_whisper/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version information."""

__version__ = "0.6.0"
__version__ = "0.7.0"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
av==10.*
ctranslate2>=3.10,<4
ctranslate2>=3.17,<4
huggingface_hub>=0.13
tokenizers==0.13.*
onnxruntime>=1.14,<2
18 changes: 18 additions & 0 deletions tests/test_transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ def test_transcribe(jfk_path):
assert segment.end == segment.words[-1].end


def test_prefix_with_timestamps(jfk_path):
model = WhisperModel("tiny")
segments, _ = model.transcribe(jfk_path, prefix="And so my fellow Americans")
segments = list(segments)

assert len(segments) == 1

segment = segments[0]

assert segment.text == (
" And so my fellow Americans ask not what your country can do for you, "
"ask what you can do for your country."
)

assert segment.start == 0
assert 10 < segment.end < 11


def test_vad(jfk_path):
model = WhisperModel("tiny")
segments, info = model.transcribe(
Expand Down

0 comments on commit c9e07ab

Please sign in to comment.