Error catching

- PCMStream.clean_up
- PCMStream.read
This commit is contained in:
Logan Cusano
2022-02-27 17:21:53 -05:00
parent 137d0ae097
commit 167c06f331

View File

@@ -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}'")