From 17c528c153edd5580ee07d3123dce6b2fe7c9640 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 27 Feb 2022 17:29:08 -0500 Subject: [PATCH] Working on bug in leaving --- sound.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/sound.py b/sound.py index 21edbbb..1060dd9 100644 --- a/sound.py +++ b/sound.py @@ -1,3 +1,5 @@ +import time + import sounddevice import sounddevice as sd from pprint import pformat @@ -15,15 +17,12 @@ class PCMStream: self.stream = None def read(self, num_bytes): - try: - # frame is 4 bytes - frames = int(num_bytes / 4) - data = self.stream.read(frames)[0] + # frame is 4 bytes + frames = int(num_bytes / 4) + data = self.stream.read(frames)[0] - # convert to pcm format - return bytes(data) - except Exception as err: - print(f"Error in PCMStream.read: '{err}'") + # convert to pcm format + return bytes(data) def change_device(self, device_ID): self.clean_up() @@ -33,14 +32,11 @@ class PCMStream: self.stream.start() def clean_up(self): - try: - if self.stream is not None: - self.stream.stop() + if self.stream is not None: + self.stream.stop() + time.sleep(.1) + self.stream.close() - self.stream.close() - - except Exception as err: - print(f"Error in PCMStream.clean_up: '{err}'")