diff --git a/sound.py b/sound.py index 0b38cfc..5d428a5 100644 --- a/sound.py +++ b/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}'")