Create audio module which allows to play sound files
This commit is contained in:
0
smnp/audio/__init__.py
Normal file
0
smnp/audio/__init__.py
Normal file
17
smnp/audio/sound.py
Normal file
17
smnp/audio/sound.py
Normal file
@@ -0,0 +1,17 @@
|
||||
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 __str__(self):
|
||||
return f"sound[{self.file}]"
|
||||
|
||||
def __repr__(self):
|
||||
return self.__str__()
|
||||
Reference in New Issue
Block a user