Working on bug in leaving

This commit is contained in:
Logan Cusano
2022-02-27 17:29:08 -05:00
parent f9594e2afe
commit 17c528c153

View File

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