Files
smnp-py/smnp/audio/sound.py
2019-07-12 21:26:06 +02:00

20 lines
462 B
Python

import sounddevice as sd
import soundfile as sf
class Sound:
def __init__(self, file):
self.file = file
self.data, self.fs = sf.read(file, dtype='float32')
def play(self):
sd.play(self.data, self.fs, blocking=True)
def __eq__(self, other):
return self.file == other.file and self.data == other.data
def __str__(self):
return f"sound[{self.file}]"
def __repr__(self):
return self.__str__()