Working on bug in leaving
This commit is contained in:
26
sound.py
26
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}'")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user