diff --git a/docs/changelog.rst b/docs/changelog.rst index eea17896..382355ef 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -11,6 +11,12 @@ :method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_channel_unban_request_create ` - Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_channel_unban_request_resolve ` / :method:`Twitchio.ext.eventsub.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 ======= diff --git a/docs/requirements.txt b/docs/requirements.txt index 0e5db09c..40eb98e7 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -7,4 +7,5 @@ sphinxext-opengraph Pygments furo pyaudio==0.2.11 -yt-dlp>=2022.2.4 \ No newline at end of file +yt-dlp>=2022.2.4 +tinytag>=1.9.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 3e706895..3c0f4d5d 100644 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/twitchio/ext/sounds/__init__.py b/twitchio/ext/sounds/__init__.py index 54989d12..24ff1b87 100644 --- a/twitchio/ext/sounds/__init__.py +++ b/twitchio/ext/sounds/__init__.py @@ -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 @@ -33,6 +34,7 @@ import pyaudio from yt_dlp import YoutubeDL +from tinytag import TinyTag __all__ = ("Sound", "AudioPlayer") @@ -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( [ @@ -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| @@ -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."""