forked from Wobbl/Wobuzz
Added opening of files via command line and added simple controls.
This commit is contained in:
parent
d089a57151
commit
ce254c8b54
6 changed files with 135 additions and 4 deletions
29
wobuzz/player/track.py
Normal file
29
wobuzz/player/track.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from pydub import AudioSegment
|
||||
from pydub.effects import normalize
|
||||
from pygame.mixer import Sound
|
||||
|
||||
|
||||
class Track:
|
||||
"""
|
||||
Class containing data for a track like file path, raw data...
|
||||
"""
|
||||
|
||||
def __init__(self, path: str, cache: bool=False):
|
||||
self.path = path
|
||||
self.cached = cache
|
||||
|
||||
self.sound = self.cache() if self.cached else None
|
||||
|
||||
def cache(self):
|
||||
audio = AudioSegment.from_mp3(self.path)
|
||||
audio = normalize(audio)
|
||||
|
||||
wav = audio.export(format="wav")
|
||||
|
||||
sound = Sound(wav)
|
||||
|
||||
# audio_bytes = io.BytesIO(wav.read())
|
||||
|
||||
return sound
|
Loading…
Add table
Add a link
Reference in a new issue