Skip to content

Sounds.ext fixes #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_channel_unban_request_create <EventSubWSClient.subscribe_channel_unban_request_create>`
- Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_channel_unban_request_resolve <EventSubClient.subscribe_channel_unban_request_resolve>` /
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_channel_unban_request_resolve <EventSubWSClient.subscribe_channel_unban_request_resolve>`
- ext.sounds
- Additions
- Added TinyTag as a dependency to support retrieving audio metadata using TinyTag in `ext.sounds.__init__.py`.
- added :method:`Twitchio.ext.sounds.rate setter.
- added :method:`Twitchio.ext.sounds.channels setter.


2.9.2
=======
Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ sphinxext-opengraph
Pygments
furo
pyaudio==0.2.11
yt-dlp>=2022.2.4
yt-dlp>=2022.2.4
tinytag>=1.9.0
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
sounds = [
"yt-dlp>=2022.2.4",
'pyaudio==0.2.11; platform_system!="Windows"',
'tinytag>=1.9.0',
]
speed = [
"ujson>=5.2,<6",
Expand Down
18 changes: 15 additions & 3 deletions twitchio/ext/sounds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import asyncio
import audioop
import dataclasses
Expand All @@ -33,6 +34,7 @@

import pyaudio
from yt_dlp import YoutubeDL
from tinytag import TinyTag


__all__ = ("Sound", "AudioPlayer")
Expand Down Expand Up @@ -173,6 +175,9 @@ def __init__(

elif isinstance(source, str):
self.title = source
tag = TinyTag.get(source)
self._rate = tag.samplerate
self._channels = tag.channels

self.proc = subprocess.Popen(
[
Expand All @@ -189,9 +194,6 @@ def __init__(
stdout=subprocess.PIPE,
)

self._channels = 2
self._rate = 48000

@classmethod
async def ytdl_search(cls, search: str, *, loop: Optional[asyncio.BaseEventLoop] = None):
"""|coro|
Expand All @@ -216,11 +218,21 @@ def channels(self):
"""The audio source channels."""
return self._channels

@channels.setter
def channels(self, channels: int):
"""Set audio source channels."""
self._channels = channels

@property
def rate(self):
"""The audio source sample rate."""
return self._rate

@rate.setter
def rate(self, rate: int):
"""Set audio source sample rate."""
self._rate = rate

@property
def source(self):
"""The raw audio source."""
Expand Down