Error catching
- PCMStream.clean_up - PCMStream.read
This commit is contained in:
18
sound.py
18
sound.py
@@ -1,3 +1,4 @@
|
||||
import sounddevice
|
||||
import sounddevice as sd
|
||||
from pprint import pformat
|
||||
|
||||
@@ -14,12 +15,15 @@ class PCMStream:
|
||||
self.stream = None
|
||||
|
||||
def read(self, num_bytes):
|
||||
# frame is 4 bytes
|
||||
frames = int(num_bytes / 4)
|
||||
data = self.stream.read(frames)[0]
|
||||
try:
|
||||
# frame is 4 bytes
|
||||
frames = int(num_bytes / 4)
|
||||
data = self.stream.read(frames)[0]
|
||||
|
||||
# convert to pcm format
|
||||
return bytes(data)
|
||||
# convert to pcm format
|
||||
return bytes(data)
|
||||
except sounddevice.PortAudioError as err:
|
||||
print(f"Error in PCMStream.read: '{err}'")
|
||||
|
||||
def change_device(self, device_ID):
|
||||
self.clean_up()
|
||||
@@ -35,8 +39,8 @@ class PCMStream:
|
||||
|
||||
self.stream.close()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error in clean_up: '{e}'")
|
||||
except sounddevice.PortAudioError as err:
|
||||
print(f"Error in PCMStream.clean_up: '{err}'")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user