-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3e6e1e
commit b3a231b
Showing
14 changed files
with
201 additions
and
11 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,20 @@ | ||
name: test | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
test_linux: | ||
name: "test on linux" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: setup | ||
run: | | ||
script/setup --dev | ||
- name: test | ||
run: | | ||
test $(script/run --version) = $(cat wyoming_vosk/VERSION) | ||
script/lint | ||
script/test |
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,10 @@ | ||
# Changelog | ||
|
||
## 1.4.0 | ||
|
||
- Add tests and Github actions | ||
- Bump wyoming to 1.5.2 | ||
|
||
## 1.3.0 | ||
|
||
- Public release |
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,2 @@ | ||
vosk==0.3.45 | ||
wyoming==1.2.0 | ||
wyoming==1.5.2 |
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 |
---|---|---|
|
@@ -3,3 +3,5 @@ flake8==6.0.0 | |
isort==5.11.3 | ||
mypy==0.991 | ||
pylint==2.15.9 | ||
pytest==7.4.4 | ||
pytest-asyncio==0.23.3 |
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
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,13 @@ | ||
#!/usr/bin/env python3 | ||
import subprocess | ||
import sys | ||
import venv | ||
from pathlib import Path | ||
|
||
_DIR = Path(__file__).parent | ||
_PROGRAM_DIR = _DIR.parent | ||
_VENV_DIR = _PROGRAM_DIR / ".venv" | ||
_TEST_DIR = _PROGRAM_DIR / "tests" | ||
|
||
context = venv.EnvBuilder().ensure_directories(_VENV_DIR) | ||
subprocess.check_call([context.env_exe, "-m", "pytest", _TEST_DIR] + sys.argv[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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,26 @@ | |
with open(requirements_path, "r", encoding="utf-8") as requirements_file: | ||
requirements = requirements_file.read().splitlines() | ||
|
||
module_name = "wyoming_vosk" | ||
module_dir = this_dir / module_name | ||
data_files = [] | ||
|
||
version_path = module_dir / "VERSION" | ||
data_files.append(version_path) | ||
version = version_path.read_text(encoding="utf-8").strip() | ||
|
||
# ----------------------------------------------------------------------------- | ||
|
||
setup( | ||
name="wyoming_vosk", | ||
version="1.3.0", | ||
name=module_name, | ||
version=version, | ||
description="Wyoming Server for Vosk", | ||
url="http://github.com/rhasspy/wyoming-vosk", | ||
author="Michael Hansen", | ||
author_email="[email protected]", | ||
license="MIT", | ||
packages=setuptools.find_packages(), | ||
package_data={module_name: [str(p.relative_to(module_dir)) for p in data_files]}, | ||
install_requires=requirements, | ||
extras_require={"limited": ["PyYAML>=6,<7", "rapidfuzz==3.3.1", "hassil==1.2.5"]}, | ||
classifiers=[ | ||
|
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,96 @@ | ||
"""Tests for wyoming-vosk""" | ||
import asyncio | ||
import re | ||
import sys | ||
import wave | ||
from asyncio.subprocess import PIPE | ||
from pathlib import Path | ||
|
||
import pytest | ||
from wyoming.asr import Transcribe, Transcript | ||
from wyoming.audio import AudioStart, AudioStop, wav_to_chunks | ||
from wyoming.event import async_read_event, async_write_event | ||
from wyoming.info import Describe, Info | ||
|
||
_DIR = Path(__file__).parent | ||
_PROGRAM_DIR = _DIR.parent | ||
_LOCAL_DIR = _PROGRAM_DIR / "local" | ||
_SAMPLES_PER_CHUNK = 1024 | ||
_MODEL = "vosk-model-small-en-us-0.15" | ||
|
||
# Need to give time for the model to download | ||
_TRANSCRIBE_TIMEOUT = 60 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_vosk() -> None: | ||
proc = await asyncio.create_subprocess_exec( | ||
sys.executable, | ||
"-m", | ||
"wyoming_vosk", | ||
"--uri", | ||
"stdio://", | ||
"--data-dir", | ||
str(_LOCAL_DIR), | ||
"--language", | ||
"en", | ||
stdin=PIPE, | ||
stdout=PIPE, | ||
) | ||
assert proc.stdin is not None | ||
assert proc.stdout is not None | ||
|
||
# Check info | ||
await async_write_event(Describe().event(), proc.stdin) | ||
while True: | ||
event = await asyncio.wait_for(async_read_event(proc.stdout), timeout=1) | ||
assert event is not None | ||
|
||
if not Info.is_type(event.type): | ||
continue | ||
|
||
info = Info.from_event(event) | ||
assert len(info.asr) == 1, "Expected one asr service" | ||
asr = info.asr[0] | ||
assert len(asr.models) > 0, "Expected at least one model" | ||
assert any(m.name == _MODEL for m in asr.models), f"Expected {_MODEL} model" | ||
break | ||
|
||
# We want to use the whisper model | ||
await async_write_event(Transcribe(name=_MODEL).event(), proc.stdin) | ||
|
||
# Test known WAV | ||
with wave.open(str(_DIR / "turn_on_the_living_room_lamp.wav"), "rb") as example_wav: | ||
await async_write_event( | ||
AudioStart( | ||
rate=example_wav.getframerate(), | ||
width=example_wav.getsampwidth(), | ||
channels=example_wav.getnchannels(), | ||
).event(), | ||
proc.stdin, | ||
) | ||
for chunk in wav_to_chunks(example_wav, _SAMPLES_PER_CHUNK): | ||
await async_write_event(chunk.event(), proc.stdin) | ||
|
||
await async_write_event(AudioStop().event(), proc.stdin) | ||
|
||
while True: | ||
event = await asyncio.wait_for( | ||
async_read_event(proc.stdout), timeout=_TRANSCRIBE_TIMEOUT | ||
) | ||
assert event is not None | ||
|
||
if not Transcript.is_type(event.type): | ||
continue | ||
|
||
transcript = Transcript.from_event(event) | ||
text = transcript.text.lower().strip() | ||
text = re.sub(r"[^a-z ]", "", text) | ||
assert text == "turn on the living room lamp" | ||
break | ||
|
||
# Need to close stdin for graceful termination | ||
proc.stdin.close() | ||
_, stderr = await proc.communicate() | ||
|
||
assert proc.returncode == 0, stderr.decode() |
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 @@ | ||
1.4.0 |
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 @@ | ||
"""Wyoming server for vosk.""" | ||
from pathlib import Path | ||
|
||
_DIR = Path(__file__).parent | ||
_VERSION_PATH = _DIR / "VERSION" | ||
|
||
__version__ = _VERSION_PATH.read_text(encoding="utf-8").strip() | ||
|
||
__all__ = ["__version__"] |
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