30 lines
627 B
Python
30 lines
627 B
Python
|
#!/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
|