forked from platypush/platypush
Removed/commented references to numpy.typing
.
That module isn't available yet on the numpy version installed on Debian `oldstable`.
This commit is contained in:
parent
193314fcd0
commit
23e53f13f0
7 changed files with 17 additions and 29 deletions
|
@ -2,7 +2,6 @@ from abc import ABC, abstractmethod
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.typing import NDArray
|
|
||||||
|
|
||||||
from ._parser import SoundParser
|
from ._parser import SoundParser
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ class SoundBase(SoundParser, ABC):
|
||||||
t_start: float = 0,
|
t_start: float = 0,
|
||||||
t_end: float = 0,
|
t_end: float = 0,
|
||||||
**_,
|
**_,
|
||||||
) -> NDArray[np.floating]:
|
): # -> NDArray[np.floating]:
|
||||||
"""
|
"""
|
||||||
Get the wave binary data associated to this sound
|
Get the wave binary data associated to this sound
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ class SoundBase(SoundParser, ABC):
|
||||||
t_end: float = 0.0,
|
t_end: float = 0.0,
|
||||||
freq_range: Optional[Tuple[float, float]] = None,
|
freq_range: Optional[Tuple[float, float]] = None,
|
||||||
freq_buckets: Optional[int] = 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
|
Get the real part of the Fourier transform associated to a time-bounded
|
||||||
sample of this sound.
|
sample of this sound.
|
||||||
|
|
|
@ -4,9 +4,6 @@ from threading import Thread
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Any, Callable, Optional
|
from typing import Any, Callable, Optional
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
from numpy.typing import NDArray
|
|
||||||
|
|
||||||
from ._mix import Mix
|
from ._mix import Mix
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +17,7 @@ class AudioGenerator(Thread):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*args,
|
*args,
|
||||||
audio_queue: Queue[NDArray[np.number]],
|
audio_queue: Queue, # Queue[NDArray[np.number]],
|
||||||
mix: Mix,
|
mix: Mix,
|
||||||
blocksize: int,
|
blocksize: int,
|
||||||
sample_rate: int,
|
sample_rate: int,
|
||||||
|
|
|
@ -3,7 +3,6 @@ import logging
|
||||||
from typing import List, Tuple, Union
|
from typing import List, Tuple, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.typing import DTypeLike, NDArray
|
|
||||||
|
|
||||||
from ...._utils import convert_nd_array
|
from ...._utils import convert_nd_array
|
||||||
from ._base import SoundBase
|
from ._base import SoundBase
|
||||||
|
@ -16,7 +15,7 @@ class Mix(SoundBase):
|
||||||
through an audio stream to an audio device
|
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)
|
super().__init__(**kwargs)
|
||||||
self._sounds: List[Sound] = []
|
self._sounds: List[Sound] = []
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
@ -64,7 +63,7 @@ class Mix(SoundBase):
|
||||||
normalize_range: Tuple[float, float] = (-1.0, 1.0),
|
normalize_range: Tuple[float, float] = (-1.0, 1.0),
|
||||||
on_clip: str = 'scale',
|
on_clip: str = 'scale',
|
||||||
**_,
|
**_,
|
||||||
) -> NDArray[np.number]:
|
): # -> NDArray[np.number]:
|
||||||
wave = None
|
wave = None
|
||||||
|
|
||||||
for sound in self._sounds:
|
for sound in self._sounds:
|
||||||
|
|
|
@ -4,9 +4,6 @@ from typing import Callable, Optional
|
||||||
|
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
from numpy.typing import NDArray
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class AudioOutputCallback:
|
class AudioOutputCallback:
|
||||||
|
@ -18,7 +15,7 @@ class AudioOutputCallback:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*args,
|
*args,
|
||||||
audio_queue: Queue[NDArray[np.number]],
|
audio_queue: Queue, # Queue[NDArray[np.number]],
|
||||||
channels: int,
|
channels: int,
|
||||||
blocksize: int,
|
blocksize: int,
|
||||||
should_stop: Callable[[], bool] = lambda: False,
|
should_stop: Callable[[], bool] = lambda: False,
|
||||||
|
@ -50,7 +47,8 @@ class AudioOutputCallback:
|
||||||
assert not status.output_underflow, 'Output underflow: increase blocksize?'
|
assert not status.output_underflow, 'Output underflow: increase blocksize?'
|
||||||
assert not status, f'Audio callback failed: {status}'
|
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():
|
if self._is_paused():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -72,7 +70,8 @@ class AudioOutputCallback:
|
||||||
outdata[:audio_length] = data[:audio_length]
|
outdata[:audio_length] = data[:audio_length]
|
||||||
|
|
||||||
# _ = time
|
# _ = time
|
||||||
def __call__(self, outdata: NDArray[np.number], frames: int, _, status):
|
# outdata: NDArray[np.number]
|
||||||
|
def __call__(self, outdata, frames: int, _, status):
|
||||||
try:
|
try:
|
||||||
self._audio_callback(outdata, frames, status)
|
self._audio_callback(outdata, frames, status)
|
||||||
except AssertionError as e:
|
except AssertionError as e:
|
||||||
|
|
|
@ -3,9 +3,7 @@ from queue import Queue
|
||||||
from threading import Event
|
from threading import Event
|
||||||
from typing import Any, Generator, Iterable, Optional, Type
|
from typing import Any, Generator, Iterable, Optional, Type
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
from numpy.typing import DTypeLike, NDArray
|
|
||||||
|
|
||||||
from ...._model import AudioState
|
from ...._model import AudioState
|
||||||
from ..._player import AudioPlayer
|
from ..._player import AudioPlayer
|
||||||
|
@ -26,7 +24,7 @@ class AudioSynthPlayer(AudioPlayer):
|
||||||
*args,
|
*args,
|
||||||
volume: float,
|
volume: float,
|
||||||
channels: int,
|
channels: int,
|
||||||
dtype: DTypeLike,
|
dtype, # : DTypeLike,
|
||||||
sounds: Optional[Iterable[Sound]] = None,
|
sounds: Optional[Iterable[Sound]] = None,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
|
@ -36,7 +34,7 @@ class AudioSynthPlayer(AudioPlayer):
|
||||||
super().__init__(*args, volume=volume, channels=channels, dtype=dtype, **kwargs)
|
super().__init__(*args, volume=volume, channels=channels, dtype=dtype, **kwargs)
|
||||||
self._generator_stopped = Event()
|
self._generator_stopped = Event()
|
||||||
self._completed_callback_event = 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
|
maxsize=self.queue_size or 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import json
|
import json
|
||||||
from typing import Final, Optional, Tuple, Union
|
from typing import Final, Optional, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.typing import NDArray
|
|
||||||
|
|
||||||
from ._base import SoundBase
|
from ._base import SoundBase
|
||||||
|
|
||||||
|
@ -103,7 +102,7 @@ class Sound(SoundBase):
|
||||||
|
|
||||||
def _get_audio_pad(
|
def _get_audio_pad(
|
||||||
self, sample_rate: float, t_start: float, t_end: float
|
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
|
Return the left and right audio pads for a given audio length as a
|
||||||
``(left, right)`` tuple of numpy zero-filled arrays.
|
``(left, right)`` tuple of numpy zero-filled arrays.
|
||||||
|
@ -120,7 +119,7 @@ class Sound(SoundBase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
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
|
Generate a raw audio wave as a numpy array of floating between -1 and 1
|
||||||
given ``x`` as a set of timestamp samples.
|
given ``x`` as a set of timestamp samples.
|
||||||
|
@ -149,7 +148,7 @@ class Sound(SoundBase):
|
||||||
t_start: float = 0,
|
t_start: float = 0,
|
||||||
t_end: float = 0,
|
t_end: float = 0,
|
||||||
**_,
|
**_,
|
||||||
) -> NDArray[np.floating]:
|
): # -> NDArray[np.floating]:
|
||||||
"""
|
"""
|
||||||
Get the wave binary data associated to this sound
|
Get the wave binary data associated to this sound
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.typing import DTypeLike, NDArray
|
|
||||||
|
|
||||||
|
|
||||||
def convert_nd_array( # pylint: disable=too-many-return-statements
|
def convert_nd_array(wave, dtype): # pylint: disable=too-many-return-statements
|
||||||
wave: NDArray[np.floating], dtype: DTypeLike
|
|
||||||
) -> NDArray[np.number]:
|
|
||||||
"""
|
"""
|
||||||
Given a wave as a series of floating point numbers, convert them to the
|
Given a wave as a series of floating point numbers, convert them to the
|
||||||
appropriate data type.
|
appropriate data type.
|
||||||
|
|
Loading…
Reference in a new issue