Skip to content
This repository was archived by the owner on Oct 6, 2026. It is now read-only.

Commit 8314489

Browse files
committed
Switch to pulling a prebuilt wheel of the sherpa-onnx fork
1 parent b4b38bb commit 8314489

9 files changed

Lines changed: 147 additions & 88 deletions

File tree

‎.github/workflows/wheels.yml‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,15 @@ jobs:
5050
- name: linux-x86_64
5151
os: ubuntu-latest
5252
python-version: "3.9"
53-
sherpa-onnx-url: https://github.com/wfloat/sherpa-onnx/releases/download/v1.12.23/sherpa_onnx-1.12.23-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
5453
- name: windows-x86_64
5554
os: windows-latest
5655
python-version: "3.10"
57-
sherpa-onnx-url: https://github.com/wfloat/sherpa-onnx/releases/download/v1.12.23/sherpa_onnx-1.12.23-cp310-cp310-win_amd64.whl
5856
- name: macos-x86_64
5957
os: macos-15-intel
6058
python-version: "3.12"
61-
sherpa-onnx-url: https://github.com/wfloat/sherpa-onnx/releases/download/v1.12.23/sherpa_onnx-1.12.23-cp312-cp312-macosx_10_15_x86_64.whl
6259
- name: macos-arm64
6360
os: macos-15
6461
python-version: "3.13"
65-
sherpa-onnx-url: https://github.com/wfloat/sherpa-onnx/releases/download/v1.12.23/sherpa_onnx-1.12.23-cp313-cp313-macosx_11_0_arm64.whl
6662

6763
steps:
6864
- name: Check out repository
@@ -81,18 +77,37 @@ jobs:
8177
with:
8278
python-version: ${{ matrix.python-version }}
8379

84-
- name: Install sherpa-onnx release wheel
80+
- name: Install wfloat artifact with dependencies
8581
shell: bash
8682
run: |
8783
python -m pip install --upgrade pip
88-
python -m pip install "${{ matrix.sherpa-onnx-url }}"
89-
90-
- name: Install wfloat artifact
91-
shell: bash
92-
run: python -m pip install --no-deps dist/*.whl
84+
python -m pip install dist/*.whl
9385
9486
- name: Run unit tests
9587
run: python -m unittest discover -s tests -v
9688

9789
- name: Run integration smoke test
9890
run: python -c "import sherpa_onnx, wfloat; import wfloat._bindings as bindings; print(wfloat.__version__); print(sherpa_onnx.__version__); print(bindings.OfflineTts)"
91+
92+
publish:
93+
name: Publish to PyPI
94+
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
95+
needs:
96+
- build
97+
- unit-tests
98+
runs-on: ubuntu-latest
99+
environment:
100+
name: pypi
101+
url: https://pypi.org/project/wfloat/
102+
permissions:
103+
id-token: write
104+
105+
steps:
106+
- name: Download artifacts
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: dist
110+
path: dist
111+
112+
- name: Publish package distributions to PyPI
113+
uses: pypa/gh-action-pypi-publish@release/v1

‎CONTRIBUTING.md‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Contributing
22

3-
`wfloat` is now a pure Python package. Native code comes from a separately
4-
installed `sherpa-onnx` wheel.
3+
`wfloat` is a pure Python package. Native code comes from the
4+
`wfloat-sherpa-onnx` dependency, which provides `import sherpa_onnx`.
55

66
## Prerequisites
77

88
- Python 3.9+
9-
- a compatible `sherpa-onnx` wheel available from GitHub Releases or another
10-
package source
119

1210
## Local setup
1311

@@ -18,18 +16,14 @@ python -m pip install --upgrade pip
1816
python -m pip install setuptools wheel build twine
1917
```
2018

21-
Install `sherpa-onnx` first if you want to exercise the low-level bindings:
22-
23-
```bash
24-
pip install https://github.com/wfloat/sherpa-onnx/releases/download/<tag>/<wheel>.whl
25-
```
26-
27-
Then install `wfloat`:
19+
Install `wfloat`:
2820

2921
```bash
3022
pip install -e .
3123
```
3224

25+
That will also install the matching `wfloat-sherpa-onnx` dependency.
26+
3327
## Build release artifacts
3428

3529
```bash
@@ -44,14 +38,13 @@ That produces:
4438

4539
## Tests
4640

47-
Unit tests do not require `sherpa-onnx`:
41+
Unit tests do not require `sherpa_onnx`:
4842

4943
```bash
5044
python -m unittest discover -s tests -v
5145
```
5246

53-
If you have installed a compatible `sherpa-onnx` wheel, you can also run a
54-
simple smoke check:
47+
You can also run a smoke check:
5548

5649
```bash
5750
python -c "import sherpa_onnx, wfloat; print(wfloat.__version__)"
@@ -63,7 +56,5 @@ CI now:
6356

6457
- builds pure Python artifacts once
6558
- installs those artifacts on each target platform
66-
- runs the unit test suite
67-
68-
After `sherpa-onnx` release assets are published, CI can add a platform-specific
69-
install step that pulls those wheel URLs before running integration smoke tests.
59+
- relies on normal dependency resolution for `wfloat-sherpa-onnx`
60+
- runs the unit test suite and an integration smoke test

‎README.md‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ Wfloat-compatible speech models and generating audio files.
55

66
## Install
77

8-
Install a compatible `sherpa-onnx` wheel first, then install `wfloat`:
8+
Install `wfloat` normally:
9+
10+
```bash
11+
pip install wfloat
12+
```
13+
14+
That will also install the matching `wfloat-sherpa-onnx` dependency from PyPI.
15+
16+
When installing from this repo locally:
917

1018
```bash
11-
pip install https://github.com/wfloat/sherpa-onnx/releases/download/<tag>/<wheel>.whl
1219
pip install ./packages/wfloat-python
1320
```
1421

@@ -33,6 +40,7 @@ result.audio.save("out.wav")
3340
## Notes
3441

3542
- `wfloat` does not build or bundle native libraries.
36-
- Low-level bindings come from the installed `sherpa-onnx` wheel.
43+
- Low-level bindings come from the installed `wfloat-sherpa-onnx` dependency,
44+
which provides `import sherpa_onnx`.
3745
- The public API is intentionally high-level; low-level native config objects
3846
are re-exported only for advanced use.

‎python/wfloat/__init__.py‎

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,19 @@
33
from ._results import Audio, GenerationResult, Timeline, TimelineChunk
44
from ._version import __version__
55

6-
_LOW_LEVEL_IMPORT_ERROR = None
7-
8-
try:
9-
from ._bindings import (
10-
GeneratedAudio,
11-
GenerationConfig,
12-
OfflineTts,
13-
OfflineTtsConfig,
14-
OfflineTtsModelConfig,
15-
OfflineTtsWfloatModelConfig,
16-
WfloatPreparedText,
17-
git_date,
18-
git_sha1,
19-
prepare_wfloat_text,
20-
version,
21-
write_wave,
22-
)
23-
except ImportError as exc:
24-
_LOW_LEVEL_IMPORT_ERROR = exc
6+
_LOW_LEVEL_EXPORTS = {
7+
"GenerationConfig",
8+
"OfflineTts",
9+
"OfflineTtsConfig",
10+
"OfflineTtsModelConfig",
11+
"OfflineTtsWfloatModelConfig",
12+
"WfloatPreparedText",
13+
"git_date",
14+
"git_sha1",
15+
"prepare_wfloat_text",
16+
"version",
17+
"write_wave",
18+
}
2519

2620

2721
__all__ = [
@@ -35,21 +29,19 @@
3529
"VALID_SIDS",
3630
"load",
3731
]
32+
__all__.extend(sorted(_LOW_LEVEL_EXPORTS))
3833

39-
if _LOW_LEVEL_IMPORT_ERROR is None:
40-
__all__.extend(
41-
[
42-
"GeneratedAudio",
43-
"GenerationConfig",
44-
"OfflineTts",
45-
"OfflineTtsConfig",
46-
"OfflineTtsModelConfig",
47-
"OfflineTtsWfloatModelConfig",
48-
"WfloatPreparedText",
49-
"git_date",
50-
"git_sha1",
51-
"prepare_wfloat_text",
52-
"version",
53-
"write_wave",
54-
]
55-
)
34+
35+
def __getattr__(name):
36+
if name not in _LOW_LEVEL_EXPORTS:
37+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
38+
39+
from . import _bindings
40+
41+
value = getattr(_bindings, name)
42+
globals()[name] = value
43+
return value
44+
45+
46+
def __dir__():
47+
return sorted(set(globals()) | _LOW_LEVEL_EXPORTS)

‎python/wfloat/_bindings.py‎

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
try:
2-
from sherpa_onnx import (
3-
GeneratedAudio,
4-
GenerationConfig,
5-
OfflineTts,
6-
OfflineTtsConfig,
7-
OfflineTtsModelConfig,
8-
OfflineTtsWfloatModelConfig,
9-
WfloatPreparedText,
10-
git_date,
11-
git_sha1,
12-
prepare_wfloat_text,
13-
version,
14-
write_wave,
15-
)
2+
import sherpa_onnx
163
except ImportError as exc:
174
raise ImportError(
18-
"Failed to import sherpa-onnx. "
19-
"Install a compatible sherpa-onnx wheel before using wfloat."
5+
"Failed to import sherpa_onnx. "
6+
"Reinstall wfloat so pip can install the matching wfloat-sherpa-onnx dependency."
207
) from exc
218

229

10+
_REQUIRED_EXPORTS = (
11+
"GenerationConfig",
12+
"OfflineTts",
13+
"OfflineTtsConfig",
14+
"OfflineTtsModelConfig",
15+
"OfflineTtsWfloatModelConfig",
16+
"WfloatPreparedText",
17+
"git_date",
18+
"git_sha1",
19+
"prepare_wfloat_text",
20+
"version",
21+
"write_wave",
22+
)
23+
24+
missing_exports = [name for name in _REQUIRED_EXPORTS if not hasattr(sherpa_onnx, name)]
25+
if missing_exports:
26+
raise ImportError(
27+
"Installed sherpa_onnx is missing required exports: "
28+
f"{', '.join(missing_exports)}. "
29+
"Reinstall wfloat so pip can install a compatible wfloat-sherpa-onnx build."
30+
)
31+
32+
33+
GenerationConfig = sherpa_onnx.GenerationConfig
34+
OfflineTts = sherpa_onnx.OfflineTts
35+
OfflineTtsConfig = sherpa_onnx.OfflineTtsConfig
36+
OfflineTtsModelConfig = sherpa_onnx.OfflineTtsModelConfig
37+
OfflineTtsWfloatModelConfig = sherpa_onnx.OfflineTtsWfloatModelConfig
38+
WfloatPreparedText = sherpa_onnx.WfloatPreparedText
39+
git_date = sherpa_onnx.git_date
40+
git_sha1 = sherpa_onnx.git_sha1
41+
prepare_wfloat_text = sherpa_onnx.prepare_wfloat_text
42+
version = sherpa_onnx.version
43+
write_wave = sherpa_onnx.write_wave
44+
45+
2346
__all__ = [
24-
"GeneratedAudio",
2547
"GenerationConfig",
2648
"OfflineTts",
2749
"OfflineTtsConfig",

‎python/wfloat/_native.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
def require_bindings() -> Any:
1616
if bindings is None:
1717
raise ImportError(
18-
"Failed to import sherpa-onnx. "
19-
"Install a compatible sherpa-onnx wheel before using wfloat."
18+
"Failed to import sherpa_onnx. "
19+
"Reinstall wfloat so pip can install the matching wfloat-sherpa-onnx dependency."
2020
) from _BINDINGS_IMPORT_ERROR
2121
return bindings
2222

‎python/wfloat/_version.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.2"
1+
__version__ = "1.0.0"

‎setup.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ def read_package_version() -> str:
3535
url="https://github.com/wfloat/wfloat-python",
3636
package_dir={"": "python"},
3737
packages=setuptools.find_packages(where="python"),
38+
install_requires=[
39+
"wfloat-sherpa-onnx==1.12.23",
40+
],
3841
include_package_data=True,
39-
install_requires=["sherpa-onnx>=1.12.23"],
4042
entry_points={
4143
"console_scripts": [
4244
"wfloat=wfloat._cli:main",

‎tests/test_basic.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import hashlib
2+
import importlib
3+
import sys
24
import tempfile
5+
import types
36
import unittest
47
import zipfile
58
from pathlib import Path
@@ -95,6 +98,32 @@ def test_audio_can_write_wave_bytes_without_numpy(self):
9598
self.assertTrue(wav_bytes.startswith(b"RIFF"))
9699
self.assertGreater(len(wav_bytes), 44)
97100

101+
def test_bindings_import_without_generated_audio(self):
102+
fake_module = types.SimpleNamespace(
103+
GenerationConfig=object(),
104+
OfflineTts=object(),
105+
OfflineTtsConfig=object(),
106+
OfflineTtsModelConfig=object(),
107+
OfflineTtsWfloatModelConfig=object(),
108+
WfloatPreparedText=object(),
109+
git_date="today",
110+
git_sha1="abc123",
111+
prepare_wfloat_text=lambda text, *args, **kwargs: text,
112+
version="1.12.23",
113+
write_wave=lambda *args, **kwargs: None,
114+
)
115+
116+
original_module = sys.modules.pop("wfloat._bindings", None)
117+
try:
118+
with mock.patch.dict(sys.modules, {"sherpa_onnx": fake_module}):
119+
bindings = importlib.import_module("wfloat._bindings")
120+
self.assertIs(bindings.OfflineTts, fake_module.OfflineTts)
121+
self.assertNotIn("GeneratedAudio", bindings.__all__)
122+
finally:
123+
sys.modules.pop("wfloat._bindings", None)
124+
if original_module is not None:
125+
sys.modules["wfloat._bindings"] = original_module
126+
98127
def test_generate_returns_audio_and_timeline(self):
99128
fake_native_tts = FakeNativeTts(sample_rate=10)
100129
model = Model("wfloat/wfloat-tts", fake_native_tts)

0 commit comments

Comments
 (0)