Skip to content

Commit 6476355

Browse files
committed
Done.
1 parent b95e82a commit 6476355

15 files changed

Lines changed: 352 additions & 176 deletions

File tree

.github/workflows/codetest.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Lint, test and notify
2+
3+
on: [push]
4+
5+
# env:
6+
# PYTHONPATH: ${{ github.workspace }}:${{ github.workspace }}/nlp4all:$PYTHONPATH
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: ["3.9", "3.10", "3.11"]
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v4
18+
id: cpmat
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
cache: 'pip'
22+
- name: Install dependencies
23+
run: |
24+
echo "PYTHONPATH=${{ github.workspace }}" >> $GITHUB_ENV
25+
python -m pip install --progress-bar off --upgrade pip
26+
pip install --progress-bar off wheel
27+
pip install --progress-bar off -r requirements-dev.txt
28+
- name: Print python os env for debugging, and pip freeze
29+
run: |
30+
printenv
31+
pip freeze
32+
- name: Analysing the code with Flake8
33+
run: |
34+
flake8
35+
# figure out why mypy doesn't work on github later
36+
- name: Type checking with mypy
37+
run: |
38+
mypy
39+
- name: Run tests with pytest
40+
run: |
41+
pytest

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2023 zeyus
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

PythonBlueBox.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

bluebox.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python
12
from bluebox import cli
23

34
if __name__ == '__main__':

bluebox/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import typing as t
22
from .freqs import BaseMF, DTMF, MF
33

4+
__version__ = '0.1.0'
5+
46
_MF: t.Dict[str, t.Type[BaseMF]] = {}
57

68

bluebox/backends/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import typing as t
22
from .base import BlueboxBackend as BlueboxBackend # noqa: F401
33
from .backend_pyaudio import PyAudioBackend as PyAudioBackend # noqa: F401
4+
from .backend_dummy import DummyBackend as DummyBackend # noqa: F401
45

56
_BACKENDS: t.Dict[str, t.Type[BlueboxBackend]] = {}
67

@@ -21,3 +22,4 @@ def list_backends() -> t.List[str]:
2122

2223

2324
register_backend('pyaudio', PyAudioBackend)
25+
register_backend('dummy', DummyBackend)

bluebox/backends/backend_dummy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ def __del__(self) -> None:
7070
def get_data(self) -> t.List[float]:
7171
"""Get the data."""
7272
return self._data
73+
74+
def clear_data(self) -> None:
75+
"""Clear the data."""
76+
self._data = []

bluebox/backends/backend_pyaudio.py

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import typing as t
77
import logging
88
import struct
9-
import pyaudio
9+
import pyaudio # type: ignore
1010
from .base import BlueboxBackend
1111

1212

@@ -28,15 +28,18 @@ def __init__(
2828
super().__init__(sample_rate, channels, amplitude, logger)
2929
self._device = device
3030

31-
def _get_stream(self) -> pyaudio.Stream:
31+
def _get_stream(
32+
self,
33+
callback: t.Optional[t.Callable] = None) -> pyaudio.Stream:
3234
"""Get the PyAudio stream."""
3335
if not self._stream_open:
3436
self._stream = pyaudio.PyAudio().open(
3537
format=pyaudio.paFloat32,
3638
channels=self._ch,
3739
rate=int(self._sr),
3840
output=True,
39-
output_device_index=self._device)
41+
output_device_index=self._device,
42+
stream_callback=callback)
4043
self._stream_open = True
4144
return self._stream
4245

@@ -85,51 +88,54 @@ def __del__(self) -> None:
8588
self.close()
8689

8790

88-
class PyAudioBackendNonBlocking(PyAudioBackend):
89-
"""PyAudioBackendNonBlocking class for the PyAudio backend."""
90-
91-
def _get_stream(self, callback: t.Callable) -> pyaudio.Stream:
92-
"""Get the PyAudio stream."""
93-
if not self._stream_open:
94-
self._stream = pyaudio.PyAudio().open(
95-
format=pyaudio.paFloat32,
96-
channels=self._ch,
97-
rate=int(self._sr),
98-
output=True,
99-
stream_callback=callback,
100-
output_device_index=self._device)
101-
self._stream_open = True
102-
return self._stream
103-
104-
@property
105-
def is_playing(self) -> bool:
106-
"""Return whether the stream is playing."""
107-
if not self._stream_open:
108-
return False
109-
return self._stream.is_active()
110-
111-
def play(self, data: t.MutableSequence[float]) -> None:
112-
"""Play the given data."""
113-
total_frames = len(data)
114-
frame_index = 0
115-
116-
def stream_callback(
117-
in_data: t.Optional[t.MutableSequence[bytes]],
118-
frame_count: int,
119-
time_info: t.Optional[dict],
120-
status: t.Optional[int]) -> t.Tuple[
121-
t.Optional[t.MutableSequence[float]],
122-
int]:
123-
nonlocal frame_index
124-
if frame_index >= total_frames:
125-
return (None, pyaudio.paComplete)
126-
frame_index += min(frame_count, total_frames - frame_index)
127-
return (
128-
data[frame_index - frame_count:frame_index],
129-
pyaudio.paContinue)
130-
131-
self._get_stream(stream_callback)
132-
133-
def play_all(self, queue: t.Iterator[t.MutableSequence[float]]) -> None:
134-
"""Not implemented. Probably should use asyncio."""
135-
raise NotImplementedError()
91+
# class PyAudioBackendNonBlocking(PyAudioBackend):
92+
# """PyAudioBackendNonBlocking class for the PyAudio backend."""
93+
94+
# def _get_stream(
95+
# self,
96+
# callback:
97+
# t.Optional[t.Callable] = None) -> pyaudio.Stream:
98+
# """Get the PyAudio stream."""
99+
# if not self._stream_open:
100+
# self._stream = pyaudio.PyAudio().open(
101+
# format=pyaudio.paFloat32,
102+
# channels=self._ch,
103+
# rate=int(self._sr),
104+
# output=True,
105+
# stream_callback=callback,
106+
# output_device_index=self._device)
107+
# self._stream_open = True
108+
# return self._stream
109+
110+
# @property
111+
# def is_playing(self) -> bool:
112+
# """Return whether the stream is playing."""
113+
# if not self._stream_open:
114+
# return False
115+
# return self._stream.is_active()
116+
117+
# def play(self, data: t.Iterator[float], close=True) -> None:
118+
# """Play the given data."""
119+
# total_frames = len(data)
120+
# frame_index = 0
121+
122+
# def stream_callback(
123+
# in_data: t.Optional[t.MutableSequence[bytes]],
124+
# frame_count: int,
125+
# time_info: t.Optional[dict],
126+
# status: t.Optional[int]) -> t.Tuple[
127+
# t.Optional[t.MutableSequence[float]],
128+
# int]:
129+
# nonlocal frame_index
130+
# if frame_index >= total_frames:
131+
# return (None, pyaudio.paComplete)
132+
# frame_index += min(frame_count, total_frames - frame_index)
133+
# return (
134+
# data[frame_index - frame_count:frame_index],
135+
# pyaudio.paContinue)
136+
137+
# self._get_stream(stream_callback)
138+
139+
# def play_all(self, queue: t.Iterator[t.MutableSequence[float]]) -> None:
140+
# """Not implemented. Probably should use asyncio."""
141+
# raise NotImplementedError()

0 commit comments

Comments
 (0)