Skip to content

Commit bd4dfb3

Browse files
feat: Add linter and a test GitHub action workflow
1 parent 052c1ee commit bd4dfb3

37 files changed

Lines changed: 549 additions & 452 deletions

.github/workflows/tests.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Tests
2+
3+
on: ['push', 'pull_request']
4+
5+
jobs:
6+
ci:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
os: [ubuntu-latest]
12+
php: [8.1, 8.2, 8.3, 8.4]
13+
dependency-version: [prefer-lowest, prefer-stable]
14+
15+
name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
16+
17+
steps:
18+
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Cache dependencies
23+
uses: actions/cache@v1
24+
with:
25+
path: ~/.composer/cache/files
26+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
27+
28+
- name: Setup PHP
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: ${{ matrix.php }}
32+
extensions: dom, mbstring, zip, ffi
33+
coverage: none
34+
35+
- name: Install Composer dependencies
36+
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
37+
38+
- name: Run Tests
39+
run: composer test

.github/workflows/windows-cuda-build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ jobs:
3434

3535
- name: Run build script
3636
run: |
37-
.\scripts\build.bat cuda ${{ github.workspace }}\whisper.cpp\
37+
cd whisper.cpp
38+
cmake -S . -B ./build -A x64 -DCMAKE_BUILD_TYPE=Release -DWHISPER_CUBLAS=ON -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF
39+
cd ./build
40+
msbuild ALL_BUILD.vcxproj -t:build -p:configuration=Release -p:platform=x64
3841
cd ${{ github.workspace }}\whisper.cpp\build\bin\Release
3942
ren whisper.dll libwhisper_cuda.dll
4043

.github/workflows/windows-native-build.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,14 @@ jobs:
2626
- name: Add msbuild to PATH
2727
uses: microsoft/setup-msbuild@v1
2828

29-
# - name: Run build script
30-
# run: |
31-
# .\scripts\build.bat cpu ${{ github.workspace }}\whisper.cpp\
32-
# cd ${{ github.workspace }}\whisper.cpp\build\bin\Release
33-
# ren whisper.dll libwhisper.dll
3429
- name: Build Windows Native Libraries
3530
run: |
3631
cd whisper.cpp
3732
cmake -S . -B ./build -A x64 -DCMAKE_BUILD_TYPE=Release -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_EXAMPLES=OFF
3833
cd ./build
3934
msbuild ALL_BUILD.vcxproj -t:build -p:configuration=Release -p:platform=x64
35+
cd ${{ github.workspace }}\whisper.cpp\build\bin\Release
36+
ren whisper.dll libwhisper.dll
4037
4138
- name: Upload Windows Build Artifacts
4239
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ playground/*
1616
.idea
1717
.fleet
1818
.vscode
19-
lib/*

Makefile

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,6 @@ define macos_build
4848
cp $(BUILD_PATH)/ggml/src/libggml.dylib $(RUNTIME_DIR)/macos-$(ARCH)$(2)/
4949
endef
5050

51-
define windows_build
52-
VSWHERE := $(shell dirname $(shell which vswhere.exe 2>/dev/null))
53-
VSINSTALL_PATH := $(shell $(VSWHERE)/vswhere.exe -products * -requires Microsoft.Component.MSBuild -property installationPath -latest)
54-
echo $(VSINSTALL_PATH)
55-
# Fallback MSBuild paths
56-
MSBUILD_CANDIDATES := \
57-
"$(MSBUILD_PATH)/MSBuild/Current/Bin/MSBuild.exe" \
58-
"$(MSBUILD_PATH)/MSBuild/15.0/Bin/MSBuild.exe" \
59-
"/c/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/MSBuild.exe" \
60-
"/c/Program Files (x86)/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/MSBuild.exe"
61-
62-
# Find first existing MSBuild
63-
MSBUILD := $(firstword $(wildcard $(MSBUILD_CANDIDATES)))
64-
echo $(MSBUILD)
65-
$(eval ARCH := $(1))
66-
$(eval BUILD_PATH := $(BUILD_DIR)/windows-$(ARCH)$(2))
67-
$(eval EXTRA_FLAGS := $(3))
68-
rm -rf "$(BUILD_PATH)"
69-
mkdir -p "$(BUILD_PATH)"
70-
$(CMAKE) -S $(WHISPER_CPP_DIR) -B $(BUILD_PATH) -A $(ARCH) $(CMAKE_COMMON_PARAMS) $(EXTRA_FLAGS)
71-
cd "$(BUILD_PATH)" && "$(MSBUILD)" ALL_BUILD.vcxproj -t:build -p:configuration=Release -p:platform=x64
72-
mkdir -p "$(RUNTIME_DIR)/windows-$(TARGET)"
73-
cp "$(BUILD_PATH)/src/Release/whisper.dll" "$(RUNTIME_DIR)/windows-$(TARGET)/"
74-
cp "$(BUILD_PATH)/ggml/src/Release/ggml.dll" "$(RUNTIME_DIR)/windows-$(TARGET)/"
75-
endef
76-
7751
# Linux build targets
7852
.PHONY: linux linux_cuda linux_openvino
7953
linux: $(addprefix linux_,$(LINUX_ARCHS))
@@ -109,18 +83,6 @@ macos_coreml: $(addprefix macos_coreml_,$(MACOS_ARCHS))
10983
macos_coreml_%:
11084
$(call macos_build,$*,_coreml,$(AVX_FLAGS) -DWHISPER_COREML=ON -DWHISPER_COREML_ALLOW_FALLBACK=ON)
11185

112-
# Windows build targets
113-
.PHONY: windows
114-
windows: $(addprefix windows_,$(WINDOWS_ARCHS))
115-
windows_%:
116-
$(call windows_build,$*,,$(AVX_FLAGS))
117-
118-
# Windows CUDA builds
119-
windows_cuda: $(addprefix windows_cuda_,$(WINDOWS_ARCHS))
120-
windows_cuda_%:
121-
$(eval ARCH := $(subst windows_cuda_,,$@))
122-
$(call windows_build,$(ARCH),_cuda,$(AVX_FLAGS) -DGGML_CUDA=ON)
123-
12486
# Clean build artifacts
12587
.PHONY: clean
12688
clean:

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"require-dev": {
1212
"symfony/var-dumper": "^7.1",
1313
"pestphp/pest": "^3.5",
14-
"mockery/mockery": "^1.6"
14+
"mockery/mockery": "^1.6",
15+
"laravel/pint": "^1.18"
1516
},
1617
"license": "MIT",
1718
"autoload": {

examples/callbacks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
declare(strict_types=1);
44

55
use Codewithkyrian\Whisper\SegmentData;
6-
use Codewithkyrian\Whisper\Whisper;
76
use Codewithkyrian\Whisper\WhisperContext;
87
use Codewithkyrian\Whisper\WhisperContextParameters;
98
use Codewithkyrian\Whisper\WhisperException;
109
use Codewithkyrian\Whisper\WhisperFullParams;
10+
1111
use function Codewithkyrian\Whisper\readAudio;
1212
use function Codewithkyrian\Whisper\toTimestamp;
1313

examples/transcription.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22

33
declare(strict_types=1);
44

5+
use Codewithkyrian\Whisper\ModelLoader;
56
use Codewithkyrian\Whisper\SegmentData;
6-
use Codewithkyrian\Whisper\Whisper;
77
use Codewithkyrian\Whisper\WhisperContext;
88
use Codewithkyrian\Whisper\WhisperContextParameters;
99
use Codewithkyrian\Whisper\WhisperException;
1010
use Codewithkyrian\Whisper\WhisperFullParams;
11+
1112
use function Codewithkyrian\Whisper\outputSrt;
1213
use function Codewithkyrian\Whisper\readAudio;
1314
use function Codewithkyrian\Whisper\toTimestamp;
1415

1516
require_once __DIR__.'/../vendor/autoload.php';
1617

17-
ini_set('memory_limit', -1);
18-
19-
$modelPath = Whisper::downloadModel('tiny.en', __DIR__.'/models');
18+
$modelPath = ModelLoader::loadModel('tiny', __DIR__.'/models');
2019
$audioPath = __DIR__.'/sounds/jfk.wav';
2120

2221
try {
@@ -27,7 +26,7 @@
2726
$fullParams = WhisperFullParams::default()
2827
->withNThreads(1)
2928
->withPrintTimestamps()
30-
->withLanguage("en")
29+
->withLanguage('en')
3130
->withTokenTimestamps();
3231

3332
$audio = readAudio($audioPath);
@@ -41,7 +40,6 @@
4140
$startTimestamp = $state->getSegmentStartTime($i);
4241
$endTimestamp = $state->getSegmentEndTime($i);
4342

44-
// Print to console
4543
printf(
4644
"[%s - %s]: %s\n",
4745
toTimestamp($startTimestamp),
@@ -55,7 +53,6 @@
5553
// Create output files
5654
$transcriptionPath = __DIR__.'/outputs/transcription.srt';
5755
outputSrt($segments, $transcriptionPath);
58-
dd(\Codewithkyrian\Whisper\timeUsage());
5956
} catch (WhisperException $e) {
6057
fprintf(STDERR, "Whisper error: %s\n", $e->getMessage());
6158
exit(1);

examples/transcription_parallel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
declare(strict_types=1);
44

5+
use Codewithkyrian\Whisper\ModelLoader;
56
use Codewithkyrian\Whisper\SegmentData;
6-
use Codewithkyrian\Whisper\Whisper;
77
use Codewithkyrian\Whisper\WhisperContext;
88
use Codewithkyrian\Whisper\WhisperContextParameters;
99
use Codewithkyrian\Whisper\WhisperException;
1010
use Codewithkyrian\Whisper\WhisperFullParams;
11+
1112
use function Codewithkyrian\Whisper\outputSrt;
1213
use function Codewithkyrian\Whisper\readAudio;
1314
use function Codewithkyrian\Whisper\toTimestamp;
@@ -16,7 +17,7 @@
1617

1718
ini_set('memory_limit', -1);
1819

19-
$modelPath = Whisper::downloadModel('tiny.en');
20+
$modelPath = ModelLoader::loadModel('tiny.en');
2021
$audioPath = __DIR__.'/sounds/jfk.wav';
2122

2223
try {

lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*

0 commit comments

Comments
 (0)