Skip to content

Commit

Permalink
Removed/commented references to numpy.typing.
Browse files Browse the repository at this point in the history
That module isn't available yet on the numpy version installed on Debian
`oldstable`.
  • Loading branch information
blacklight committed Oct 23, 2023
1 parent 193314f commit 23e53f1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 29 deletions.
5 changes: 2 additions & 3 deletions platypush/plugins/sound/_streams/_player/_synth/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Optional, Tuple

import numpy as np
from numpy.typing import NDArray

from ._parser import SoundParser

Expand Down Expand Up @@ -31,7 +30,7 @@ def get_wave(
t_start: float = 0,
t_end: float = 0,
**_,
) -> NDArray[np.floating]:
): # -> NDArray[np.floating]:
"""
Get the wave binary data associated to this sound
Expand All @@ -50,7 +49,7 @@ def fft(
t_end: float = 0.0,
freq_range: Optional[Tuple[float, float]] = None,
freq_buckets: Optional[int] = None,
) -> NDArray[np.floating]:
): # -> NDArray[np.floating]:
"""
Get the real part of the Fourier transform associated to a time-bounded
sample of this sound.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from time import time
from typing import Any, Callable, Optional

import numpy as np
from numpy.typing import NDArray

from ._mix import Mix


Expand All @@ -20,7 +17,7 @@ class AudioGenerator(Thread):
def __init__(
self,
*args,
audio_queue: Queue[NDArray[np.number]],
audio_queue: Queue, # Queue[NDArray[np.number]],
mix: Mix,
blocksize: int,
sample_rate: int,
Expand Down
5 changes: 2 additions & 3 deletions platypush/plugins/sound/_streams/_player/_synth/_mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import List, Tuple, Union

import numpy as np
from numpy.typing import DTypeLike, NDArray

from ...._utils import convert_nd_array
from ._base import SoundBase
Expand All @@ -16,7 +15,7 @@ class Mix(SoundBase):
through an audio stream to an audio device
"""

def __init__(self, *sounds, channels: int, dtype: DTypeLike, **kwargs):
def __init__(self, *sounds, channels: int, dtype, **kwargs):
super().__init__(**kwargs)
self._sounds: List[Sound] = []
self.logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,7 +63,7 @@ def get_wave(
normalize_range: Tuple[float, float] = (-1.0, 1.0),
on_clip: str = 'scale',
**_,
) -> NDArray[np.number]:
): # -> NDArray[np.number]:
wave = None

for sound in self._sounds:
Expand Down
11 changes: 5 additions & 6 deletions platypush/plugins/sound/_streams/_player/_synth/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

import sounddevice as sd

import numpy as np
from numpy.typing import NDArray


# pylint: disable=too-few-public-methods
class AudioOutputCallback:
Expand All @@ -18,7 +15,7 @@ class AudioOutputCallback:
def __init__(
self,
*args,
audio_queue: Queue[NDArray[np.number]],
audio_queue: Queue, # Queue[NDArray[np.number]],
channels: int,
blocksize: int,
should_stop: Callable[[], bool] = lambda: False,
Expand Down Expand Up @@ -50,7 +47,8 @@ def _check_status(self, frames: int, status):
assert not status.output_underflow, 'Output underflow: increase blocksize?'
assert not status, f'Audio callback failed: {status}'

def _audio_callback(self, outdata: NDArray[np.number], frames: int, status):
# outdata: NDArray[np.number]
def _audio_callback(self, outdata, frames: int, status):
if self._is_paused():
return

Expand All @@ -72,7 +70,8 @@ def _audio_callback(self, outdata: NDArray[np.number], frames: int, status):
outdata[:audio_length] = data[:audio_length]

# _ = time
def __call__(self, outdata: NDArray[np.number], frames: int, _, status):
# outdata: NDArray[np.number]
def __call__(self, outdata, frames: int, _, status):
try:
self._audio_callback(outdata, frames, status)
except AssertionError as e:
Expand Down
6 changes: 2 additions & 4 deletions platypush/plugins/sound/_streams/_player/_synth/_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from threading import Event
from typing import Any, Generator, Iterable, Optional, Type

import numpy as np
import sounddevice as sd
from numpy.typing import DTypeLike, NDArray

from ...._model import AudioState
from ..._player import AudioPlayer
Expand All @@ -26,7 +24,7 @@ def __init__(
*args,
volume: float,
channels: int,
dtype: DTypeLike,
dtype, # : DTypeLike,
sounds: Optional[Iterable[Sound]] = None,
**kwargs
):
Expand All @@ -36,7 +34,7 @@ def __init__(
super().__init__(*args, volume=volume, channels=channels, dtype=dtype, **kwargs)
self._generator_stopped = Event()
self._completed_callback_event = Event()
self._audio_queue: Queue[NDArray[np.number]] = Queue(
self._audio_queue = Queue( # Queue[NDArray[np.number]]
maxsize=self.queue_size or 0
)

Expand Down
9 changes: 4 additions & 5 deletions platypush/plugins/sound/_streams/_player/_synth/_sound.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from enum import Enum
import json
from typing import Final, Optional, Tuple, Union
from typing import Final, Optional, Union

import numpy as np
from numpy.typing import NDArray

from ._base import SoundBase

Expand Down Expand Up @@ -103,7 +102,7 @@ def _get_right_audio_pad(

def _get_audio_pad(
self, sample_rate: float, t_start: float, t_end: float
) -> Tuple[NDArray[np.floating], NDArray[np.floating]]:
): # -> Tuple[NDArray[np.floating], NDArray[np.floating]]:
"""
Return the left and right audio pads for a given audio length as a
``(left, right)`` tuple of numpy zero-filled arrays.
Expand All @@ -120,7 +119,7 @@ def _get_audio_pad(
)
)

def _generate_wave(self, x: NDArray[np.floating]):
def _generate_wave(self, x):
"""
Generate a raw audio wave as a numpy array of floating between -1 and 1
given ``x`` as a set of timestamp samples.
Expand Down Expand Up @@ -149,7 +148,7 @@ def get_wave(
t_start: float = 0,
t_end: float = 0,
**_,
) -> NDArray[np.floating]:
): # -> NDArray[np.floating]:
"""
Get the wave binary data associated to this sound
Expand Down
5 changes: 1 addition & 4 deletions platypush/plugins/sound/_utils/_convert.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import numpy as np
from numpy.typing import DTypeLike, NDArray


def convert_nd_array( # pylint: disable=too-many-return-statements
wave: NDArray[np.floating], dtype: DTypeLike
) -> NDArray[np.number]:
def convert_nd_array(wave, dtype): # pylint: disable=too-many-return-statements
"""
Given a wave as a series of floating point numbers, convert them to the
appropriate data type.
Expand Down

0 comments on commit 23e53f1

Please sign in to comment.