Skip to content

Commit

Permalink
Update 0.5.12 (#12)
Browse files Browse the repository at this point in the history
- Refactoring function `__callback__(...)`
- Update function `recofigurate(...)`
- Fixed typing
  • Loading branch information
romanin-rf authored Jan 3, 2025
2 parents a304143 + 5b5e316 commit 300db71
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 126 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "seaplayer-audio"
version = "0.5.5"
version = "0.5.12"
description = "A library for async/sync playback audio."
repository = "https://github.com/romanin-rf/seaplayer-audio"
authors = ["Romanin <[email protected]>"]
Expand Down
9 changes: 6 additions & 3 deletions seaplayer_audio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
AsyncStreamerBase, StreamerBase, StreamerState,
AsyncSoundDeviceStreamerBase, SoundDeviceStreamerBase
)
from .audiosources import FileAudioSource, AsyncFileAudioSource
from .audiosources import (
FileAudioSource, AsyncFileAudioSource
)
from .streamers import (
ThreadSoundDeviceStreamer, AsyncThreadSoundDeviceStreamer,
CallbackSoundDeviceStreamer, AsyncCallbackSoundDeviceStreamer
CallbackSoundDeviceStreamer, AsyncCallbackSoundDeviceStreamer, CallbackSettingsFlag
)
from ._types import AudioSamplerate, AudioChannels, AudioDType, AudioFormat, AudioSubType, AudioEndians


__all__ = [
'AsyncAudioSourceBase', 'AudioSourceBase', 'AudioSourceMetadata',
'AsyncStreamerBase', 'StreamerBase', 'StreamerState',
'AsyncSoundDeviceStreamerBase', 'SoundDeviceStreamerBase',
'ThreadSoundDeviceStreamer', 'AsyncThreadSoundDeviceStreamer',
'CallbackSoundDeviceStreamer', 'AsyncCallbackSoundDeviceStreamer',
'CallbackSoundDeviceStreamer', 'AsyncCallbackSoundDeviceStreamer', 'CallbackSettingsFlag',
'FileAudioSource', 'AsyncFileAudioSource',
'AudioSamplerate', 'AudioChannels', 'AudioDType', 'AudioFormat', 'AudioSubType', 'AudioEndians'
]
9 changes: 8 additions & 1 deletion seaplayer_audio/_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import numpy as np
from pathlib import Path
from email.message import Message
from io import BufferedReader
from http.client import HTTPResponse
from numpy import ndarray
# > Typing
from typing_extensions import (
Tuple, Any,
Coroutine, Awaitable, Callable,
Expand All @@ -25,13 +28,17 @@
'float32', 'float64', 'float80', 'float96', 'float128', 'float256'
]

# ! Numpy Types

SupportNDArray = ndarray[Any, Union[np.int16, np.int32, np.float32, np.float64]]

# ! IO Types

FilePathType: TypeAlias = Union[str, Path]

# ! Audio Types

AudioChannels: TypeAlias = Literal[1, 2]
AudioChannels: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12]
AudioSamplerate: TypeAlias = Literal[
8000, 11025, 16000, 22050, 32000, 44100, 48000, 96000, 192000
]
Expand Down
8 changes: 7 additions & 1 deletion seaplayer_audio/audiosources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
from .fileaudiosource import FileAudioSource, AsyncFileAudioSource
from .urlio import URLIO
from .urlio import URLIO


__all__ = [
'FileAudioSource', 'AsyncFileAudioSource',
'URLIO'
]
8 changes: 4 additions & 4 deletions seaplayer_audio/audiosources/urlio.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,18 @@ def seek(self, offset: int, whence: int=0, /) -> int:

# ^ IO Methods (NOT IMPLEMENTED)

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def write(self):
raise OSError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def writelines(self, lines: Iterable[bytes], /):
raise OSError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def fileno(self):
raise OSError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def flush(self):
raise NotImplementedError
1 change: 1 addition & 0 deletions seaplayer_audio/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .sndstreamer import SoundDeviceStreamerBase, AsyncSoundDeviceStreamerBase
from .audiosource import AudioSourceBase, AsyncAudioSourceBase, AudioSourceMetadata


__all__ = [
'AudioSourceBase', 'AsyncAudioSourceBase', 'AudioSourceMetadata',
'StreamerState', 'StreamerBase', 'AsyncStreamerBase',
Expand Down
56 changes: 28 additions & 28 deletions seaplayer_audio/base/audiosource.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,89 +41,89 @@ class AudioSourceBase(IOBase, Reprable):

# ^ Methods

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def __iter__(self) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise NotImplementedError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def __next__(self) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise NotImplementedError

def writable(self) -> bool:
return False

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def write(self, *args, **kwargs) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise OSError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def writelines(self, lines: Iterable[Any]) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise OSError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def truncate(self, size: Optional[int]=None) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise NotImplementedError

def isatty(self) -> bool:
return False

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def flush(self) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise NotImplementedError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
def fileno(self) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise OSError

# ! Audio Source Class (async)

class AsyncAudioSourceBase(AudioSourceBase):
"""Base class for working with audio sources (async)."""

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
async def __aiter__(self) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise NotImplementedError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
async def __anext__(self) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise NotImplementedError

def writable(self) -> bool:
return False

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
async def write(self, *args, **kwargs) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise OSError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
async def writelines(self, lines: Iterable[Any]) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise OSError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
async def truncate(self, size = ...) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise NotImplementedError

async def isatty(self) -> bool:
return False

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
async def flush(self) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise NotImplementedError

@deprecated('!!! NOT IMPLEMENTED !!!')
@deprecated('NOT IMPLEMENTED')
async def fileno(self) -> NoReturn:
"""!!! NOT IMPLEMENTED !!!"""
"""NOT IMPLEMENTED"""
raise OSError
20 changes: 19 additions & 1 deletion seaplayer_audio/base/sndstreamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def __init__(
) -> None:
super().__init__(samplerate, channels, dtype, closefd)
self.device = device

def reconfigure(self,
samplerate: Optional[AudioSamplerate]=None,
channels: Optional[AudioChannels]=None,
dtype: Optional[AudioDType]=None,
device: Optional[int]=None,
) -> None:
super().reconfigure(samplerate, channels, dtype)
self.device = device if (device is not None) else self.device

# ^ Async SoundDevice Streamer Base

Expand All @@ -34,4 +43,13 @@ def __init__(
device: Optional[int]=None
) -> None:
super().__init__(samplerate, channels, dtype, closefd, loop)
self.device = device
self.device = device

def reconfigure(self,
samplerate: Optional[AudioSamplerate]=None,
channels: Optional[AudioChannels]=None,
dtype: Optional[AudioDType]=None,
device: Optional[int]=None,
) -> None:
super().reconfigure(samplerate, channels, dtype)
self.device = device if (device is not None) else self.device
6 changes: 3 additions & 3 deletions seaplayer_audio/base/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def reconfigure(self,
channels: Optional[AudioChannels]=None,
dtype: Optional[AudioDType]=None,
) -> None:
self.samplerate = samplerate or 44100
self.channels = channels or 2
self.dtype = dtype or 'float32'
self.samplerate = samplerate if (samplerate is not None) else self.samplerate
self.channels = channels if (channels is not None) else self.channels
self.dtype = dtype if (dtype is not None) else self.dtype

def run(self) -> None:
raise NotImplementedError
Expand Down
Empty file removed seaplayer_audio/exceptions.py
Empty file.
4 changes: 2 additions & 2 deletions seaplayer_audio/streamers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .threadstreamersnd import ThreadSoundDeviceStreamer, AsyncThreadSoundDeviceStreamer
from .callbackstreamersnd import CallbackSoundDeviceStreamer, AsyncCallbackSoundDeviceStreamer
from .callbackstreamersnd import CallbackSoundDeviceStreamer, AsyncCallbackSoundDeviceStreamer, CallbackSettingsFlag


__all__ = [
'ThreadSoundDeviceStreamer', 'AsyncThreadSoundDeviceStreamer',
'CallbackSoundDeviceStreamer', 'AsyncCallbackSoundDeviceStreamer'
'CallbackSoundDeviceStreamer', 'AsyncCallbackSoundDeviceStreamer', 'CallbackSettingsFlag'
]
Loading

0 comments on commit 300db71

Please sign in to comment.