Skip to content

Commit e7e2047

Browse files
committed
Added tinytag dependency to retrieve audio file metadata
This allows for automatic detetction of local audio files' sample rate and audio channels so the files play correctly
1 parent 215e5b2 commit e7e2047

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

twitchio/ext/sounds/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import pyaudio
3535
from yt_dlp import YoutubeDL
36+
from tinytag import TinyTag
3637

3738

3839
__all__ = ("Sound", "AudioPlayer")
@@ -173,6 +174,9 @@ def __init__(
173174

174175
elif isinstance(source, str):
175176
self.title = source
177+
tag = TinyTag.get(source)
178+
self._rate = tag.samplerate
179+
self._channels = tag.channels
176180

177181
self.proc = subprocess.Popen(
178182
[
@@ -189,8 +193,6 @@ def __init__(
189193
stdout=subprocess.PIPE,
190194
)
191195

192-
self._channels = 2
193-
self._rate = 48000
194196

195197
@classmethod
196198
async def ytdl_search(cls, search: str, *, loop: Optional[asyncio.BaseEventLoop] = None):

0 commit comments

Comments
 (0)