forked from SYSTRAN/faster-whisper
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run some automatic tests with GitHub Actions (SYSTRAN#68)
- Loading branch information
1 parent
52264f2
commit 66efd02
Showing
9 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- v* | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
check-code-format: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install module | ||
run: | | ||
pip install wheel | ||
pip install .[dev] --extra-index-url https://download.pytorch.org/whl/cpu | ||
- name: Check code format with Black | ||
run: | | ||
black --check . | ||
- name: Check imports order with isort | ||
run: | | ||
isort --check-only . | ||
- name: Check code style with Flake8 | ||
if: ${{ always() }} | ||
run: | | ||
flake8 . | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install module | ||
run: | | ||
pip install wheel | ||
pip install .[dev] --extra-index-url https://download.pytorch.org/whl/cpu | ||
- name: Run pytest | ||
run: | | ||
pytest -v tests/test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
from faster_whisper.audio import decode_audio | ||
from faster_whisper.transcribe import WhisperModel | ||
from faster_whisper.utils import format_timestamp | ||
|
||
__all__ = [ | ||
"decode_audio", | ||
"WhisperModel", | ||
"format_timestamp", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[flake8] | ||
max-line-length = 100 | ||
ignore = | ||
E203, | ||
W503, | ||
|
||
[isort] | ||
profile=black | ||
lines_between_types=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
import ctranslate2 | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def data_dir(): | ||
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "data") | ||
|
||
|
||
@pytest.fixture | ||
def jfk_path(data_dir): | ||
return os.path.join(data_dir, "jfk.flac") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def tiny_model_dir(tmp_path_factory): | ||
model_path = str(tmp_path_factory.mktemp("data") / "model") | ||
convert_model("tiny", model_path) | ||
return model_path | ||
|
||
|
||
def convert_model(size, output_dir): | ||
name = "openai/whisper-%s" % size | ||
|
||
ctranslate2.converters.TransformersConverter( | ||
name, | ||
copy_files=["tokenizer.json"], | ||
load_as_float16=True, | ||
).convert(output_dir, quantization="float16") |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from faster_whisper import WhisperModel | ||
|
||
|
||
def test_transcribe(tiny_model_dir, jfk_path): | ||
model = WhisperModel(tiny_model_dir) | ||
segments, info = model.transcribe(jfk_path, word_timestamps=True) | ||
|
||
assert info.language == "en" | ||
assert info.language_probability > 0.9 | ||
assert info.duration == 11 | ||
|
||
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.text == "".join(word.word for word in segment.words) | ||
assert segment.start == segment.words[0].start | ||
assert segment.end == segment.words[-1].end |