Skip to content

Commit 2405ddd

Browse files
authored
Added new dependency for resolving stereo channels and sample rate from audio files. Added setters for rate and channel to expose them incase the meta data is incorrect. (#454)
1 parent 9fe0a85 commit 2405ddd

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

docs/changelog.rst

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_channel_unban_request_create <EventSubWSClient.subscribe_channel_unban_request_create>`
1818
- Added :method:`Twitchio.ext.eventsub.EventSubClient.subscribe_channel_unban_request_resolve <EventSubClient.subscribe_channel_unban_request_resolve>` /
1919
:method:`Twitchio.ext.eventsub.EventSubWSClient.subscribe_channel_unban_request_resolve <EventSubWSClient.subscribe_channel_unban_request_resolve>`
20+
- ext.sounds
21+
- Additions
22+
- Added TinyTag as a dependency to support retrieving audio metadata using TinyTag in `ext.sounds.__init__.py`.
23+
- added :method:`Twitchio.ext.sounds.rate setter.
24+
- added :method:`Twitchio.ext.sounds.channels setter.
25+
2026
2127
2.9.2
2228
=======

docs/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ sphinxext-opengraph
77
Pygments
88
furo
99
pyaudio==0.2.11
10-
yt-dlp>=2022.2.4
10+
yt-dlp>=2022.2.4
11+
tinytag>=1.9.0

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
sounds = [
5252
"yt-dlp>=2022.2.4",
5353
'pyaudio==0.2.11; platform_system!="Windows"',
54+
'tinytag>=1.9.0',
5455
]
5556
speed = [
5657
"ujson>=5.2,<6",

twitchio/ext/sounds/__init__.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
2222
"""
23+
2324
import asyncio
2425
import audioop
2526
import dataclasses
@@ -33,6 +34,7 @@
3334

3435
import pyaudio
3536
from yt_dlp import YoutubeDL
37+
from tinytag import TinyTag
3638

3739

3840
__all__ = ("Sound", "AudioPlayer")
@@ -173,6 +175,9 @@ def __init__(
173175

174176
elif isinstance(source, str):
175177
self.title = source
178+
tag = TinyTag.get(source)
179+
self._rate = tag.samplerate
180+
self._channels = tag.channels
176181

177182
self.proc = subprocess.Popen(
178183
[
@@ -189,9 +194,6 @@ def __init__(
189194
stdout=subprocess.PIPE,
190195
)
191196

192-
self._channels = 2
193-
self._rate = 48000
194-
195197
@classmethod
196198
async def ytdl_search(cls, search: str, *, loop: Optional[asyncio.BaseEventLoop] = None):
197199
"""|coro|
@@ -216,11 +218,21 @@ def channels(self):
216218
"""The audio source channels."""
217219
return self._channels
218220

221+
@channels.setter
222+
def channels(self, channels: int):
223+
"""Set audio source channels."""
224+
self._channels = channels
225+
219226
@property
220227
def rate(self):
221228
"""The audio source sample rate."""
222229
return self._rate
223230

231+
@rate.setter
232+
def rate(self, rate: int):
233+
"""Set audio source sample rate."""
234+
self._rate = rate
235+
224236
@property
225237
def source(self):
226238
"""The raw audio source."""

0 commit comments

Comments
 (0)