Skip to content

Commit

Permalink
Start separating builds for audio tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybchris committed Apr 16, 2024
1 parent 5cc2779 commit 5cf69d9
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 348 deletions.
54 changes: 52 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
build-unit:
test-unit:
runs-on: ubuntu-latest

strategy:
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
run: |
poetry run covcheck coverage.xml --config pyproject.toml --group unit
build-service:
test-service:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -124,3 +124,53 @@ jobs:
shell: bash
run: |
poetry run covcheck coverage.xml --config pyproject.toml --group service
test-service-audio:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Python 3.10 Setup
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install system dependencies
shell: bash
run: |
sudo apt-get --yes update
sudo apt-get --yes install libasound2-dev libportaudio2
- name: Install Python dependencies
shell: bash
run: |
pip install poetry
if [ -d /poetryenvs ]; then rm -rf ~/poetryenvs; fi
poetry config virtualenvs.path ~/poetryenvs
poetry install -E audio
- name: Run pytest
shell: bash
env:
HUME_DEV_API_KEY: ${{ secrets.HUME_DEV_API_KEY }}
run: |
poetry run pytest tests --cov=hume --cov-report=html --cov-report=xml --cov-branch -m service
- name: Upload HTML Coverage
uses: actions/upload-artifact@v2
with:
name: hume-service-coverage-html
path: hume/htmlcov

- name: Upload XML Coverage
uses: actions/upload-artifact@v2
with:
name: hume-service-coverage-xml
path: hume/coverage.xml

- name: Check Coverage
shell: bash
run: |
poetry run covcheck coverage.xml --config pyproject.toml --group service
21 changes: 16 additions & 5 deletions hume/_voice/microphone/microphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
import dataclasses
from typing import AsyncIterator, ClassVar, Iterator, Optional

import _cffi_backend as cffi_backend
import sounddevice
from _cffi_backend import _CDataBase as CDataBase # pylint: disable=no-name-in-module
from sounddevice import CallbackFlags, RawInputStream

from hume._voice.microphone.asyncio_utilities import Stream
from hume.error.hume_client_exception import HumeClientException

try:
import _cffi_backend as cffi_backend
import sounddevice
from _cffi_backend import _CDataBase as CDataBase # pylint: disable=no-name-in-module
from sounddevice import CallbackFlags, RawInputStream

HAS_AUDIO_DEPENDENCIES = True
except ModuleNotFoundError:
HAS_AUDIO_DEPENDENCIES = False


@dataclasses.dataclass
Expand All @@ -26,6 +32,11 @@ class Microphone:
@classmethod
@contextlib.contextmanager
def context(cls, *, device: Optional[int] = DEFAULT_DEVICE) -> Iterator["Microphone"]:
if not HAS_AUDIO_DEPENDENCIES:
raise HumeClientException(
'Run `pip install "hume[audio]"` to install dependencies required to use microphone playback.'
)

if device is None:
device = sounddevice.default.device[0]
sound_device = sounddevice.query_devices(device=device)
Expand Down
Loading

0 comments on commit 5cf69d9

Please sign in to comment.