Skip to content

Commit

Permalink
Merge pull request #94 from AIWintermuteAI/updating-to-fix-CI
Browse files Browse the repository at this point in the history
Fix the CI builds
  • Loading branch information
AIWintermuteAI authored Jul 17, 2024
2 parents 81cb0e9 + b078600 commit cc9d098
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 26 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches:
- develop
schedule:
- cron: '00 12 * * 1' # Monday 12 PM UTC
- cron: '00 12 1 * *' # First day of each month 12 PM UTC
concurrency:
group: ci-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
Expand All @@ -23,9 +23,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- os: 'windows-latest'
os: [ubuntu-latest, macos-latest]
name: Integration tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 90
Expand All @@ -37,7 +35,7 @@ jobs:
- name: Setup CI
uses: ./.github/actions/setup-repo
with:
python-version: '3.8' # sync with default version in WORKSPACE.
python-version: '3.11.8' # sync with default version in WORKSPACE.
- name: Install development dependencies and bindings
run: |
bazel run pypi_update
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/submodule-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ name: Submodule Updates
on:
workflow_dispatch:
schedule:
- cron: '00 12 * * 1' # Monday 12 PM UTC
- cron: '00 12 1 * *' # First day of each month 12 PM UTC

###############
# Set the Job #
###############
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
pull_request:
branches:
- develop
schedule:
- cron: '00 12 1 * *' # First day of each month 12 PM UTC
concurrency:
group: wheels-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
Expand Down Expand Up @@ -51,10 +53,11 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.10', '3.11']
os: ['ubuntu-latest', 'macos-latest']
python-version: ['3.10', '3.11.8']
exclude:
- os: 'windows-latest'
- os: 'macos-latest'
python-version: '3.10'
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ bun.lockb
*.bin

src/whispercpp/__about__.py
.vscode/settings.json
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ py_wheel(
homepage = "https://github.com/aarnphm/whispercpp",
license = "Apache 2.0",
platform = select({
"//:aarch64-apple-darwin": "macosx_10_9_arm64",
"//:aarch64-apple-darwin": "macosx_14_0_arm64",
"//:aarch64-unknown-linux-gnu": "manylinux2014_aarch64",
"//:x86_64-apple-darwin": "macosx_10_9_x86_64",
"//:x86_64-apple-darwin": "macosx_14_0_x86_64",
"//:x86_64-pc-windows-msvc": "win_amd64",
"//:x86_64-unknown-linux-gnu": "manylinux2014_x86_64",
}),
Expand Down
1 change: 0 additions & 1 deletion examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ py_test(
"//src/whispercpp:whispercpp_lib",
requirement("bazel-runfiles"),
requirement("numpy"),
requirement("pydub"),
],
)
2 changes: 1 addition & 1 deletion examples/bindings/explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def main(argv: list[str]) -> int:
assert Path(path).exists()
params = get_model().params.with_print_realtime(True).build()
assert _model is not None
_model.context.full(params, w.api.load_wav_file(Path(path).__fspath__()).mono)
_model.context.full(params, w.api.load_wav_file_mono(Path(path).__fspath__()))
return 0


Expand Down
3 changes: 1 addition & 2 deletions requirements/pypi.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pydub==0.25.1
ruff
black
bazel-runfiles==0.19.0
Expand All @@ -10,4 +9,4 @@ pytest-xdist[psutil]
pytest-asyncio
build
virtualenv
twine
twine
6 changes: 3 additions & 3 deletions rules/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def internal_deps():
# Override python rules defined under @com_github_bentoml_plugins
http_archive(
name = "rules_python",
sha256 = "b0a45e1fdaade7ac4975a9dfa08a170b78e209ba717946f7d397a75dc8a9fda6",
strip_prefix = "rules_python-4e3d01c9f6a6cda0fb34b7c2961d6b1ef5313218",
url = "https://github.com/bazelbuild/rules_python/archive/4e3d01c9f6a6cda0fb34b7c2961d6b1ef5313218.tar.gz",
sha256 = "3d6fe72f1a056b3462f02afba5049210acbaec131087fb19082fa6792198a9fa",
strip_prefix = "rules_python-084b877c98b580839ceab2b071b02fc6768f3de6",
url = "https://github.com/bazelbuild/rules_python/archive/084b877c98b580839ceab2b071b02fc6768f3de6.tar.gz",
)
2 changes: 1 addition & 1 deletion src/whispercpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def transcribe_from_file(
Transcribed text.
"""
return self.transcribe(
api.load_wav_file(filename).mono, num_proc=num_proc, strict=strict
api.load_wav_file_mono(filename), num_proc=num_proc, strict=strict
)

def stream_transcribe(
Expand Down
24 changes: 24 additions & 0 deletions src/whispercpp/api_cpp2py_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ WavFileWrapper WavFileWrapper::load_wav_file(const char *filename) {
return WavFileWrapper(&pcmf32, &pcmf32s);
}

std::vector<std::vector<float>> load_wav_file_stereo(const char *filename) {
std::vector<float> pcmf32;
std::vector<std::vector<float>> pcmf32s;
if (!::read_wav(filename, pcmf32, pcmf32s, true)) {
throw std::runtime_error("Failed to load wav file");
}
return pcmf32s;
}

std::vector<float> load_wav_file_mono(const char *filename) {
std::vector<float> pcmf32;
std::vector<std::vector<float>> pcmf32s;
if (!::read_wav(filename, pcmf32, pcmf32s, false)) {
throw std::runtime_error("Failed to load wav file");
}
return pcmf32;
}

namespace py = pybind11;
using namespace pybind11::literals;

Expand Down Expand Up @@ -58,6 +76,12 @@ PYBIND11_MODULE(api_cpp2py_export, m) {
whisper_sampling_strategy::WHISPER_SAMPLING_BEAM_SEARCH)
.export_values();

m.def("load_wav_file_stereo", load_wav_file_stereo, "filename"_a,
py::return_value_policy::reference);

m.def("load_wav_file_mono", load_wav_file_mono, "filename"_a,
py::return_value_policy::reference);

m.def("load_wav_file", &WavFileWrapper::load_wav_file, "filename"_a,
py::return_value_policy::reference);

Expand Down
1 change: 0 additions & 1 deletion tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ py_test(
"//src/whispercpp:whispercpp_lib",
requirement("bazel-runfiles"),
requirement("numpy"),
requirement("pydub"),
],
)

Expand Down
14 changes: 9 additions & 5 deletions tests/export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest as p

import whispercpp as w
from pydub import AudioSegment as am
import wave

if t.TYPE_CHECKING:
import numpy as np
Expand All @@ -21,10 +21,14 @@

def preprocess(file: Path, sample_rate: int = 16000) -> NDArray[np.float32]:

sound = am.from_file(file, format='wav', frame_rate=sample_rate)
sound = sound.set_frame_rate(sample_rate).get_array_of_samples()
sound = wave.open(str(file), "rb")
nchannels = sound.getnchannels()
N = sound.getnframes()
dstr = sound.readframes(N*nchannels)
data = np.fromstring(dstr, np.int16)
data = data.reshape(-1, nchannels)

return np.frombuffer(sound, np.int16).flatten().astype(np.float32) / 32768.0
return data.flatten().astype(np.float32) / 32768.0

def test_invalid_models():
with p.raises(RuntimeError):
Expand Down Expand Up @@ -73,7 +77,7 @@ def test_from_params_file(models: str):
def test_load_wav_file():
np.testing.assert_almost_equal(
preprocess(JFK_WAV),
w.api.load_wav_file(str(JFK_WAV.resolve())).mono,
w.api.load_wav_file_mono(str(JFK_WAV.resolve())),
)

def transcribe_strict():
Expand Down

0 comments on commit cc9d098

Please sign in to comment.