Handle failure on systems without microphones
Catch the OSError and print a WARN log.
This commit is contained in:
@@ -66,6 +66,7 @@ class Client:
|
|||||||
self.timestamp_offset = 0.0
|
self.timestamp_offset = 0.0
|
||||||
self.audio_bytes = None
|
self.audio_bytes = None
|
||||||
self.p = pyaudio.PyAudio()
|
self.p = pyaudio.PyAudio()
|
||||||
|
try:
|
||||||
self.stream = self.p.open(
|
self.stream = self.p.open(
|
||||||
format=self.format,
|
format=self.format,
|
||||||
channels=self.channels,
|
channels=self.channels,
|
||||||
@@ -73,6 +74,9 @@ class Client:
|
|||||||
input=True,
|
input=True,
|
||||||
frames_per_buffer=self.chunk,
|
frames_per_buffer=self.chunk,
|
||||||
)
|
)
|
||||||
|
except OSError as error:
|
||||||
|
print(f"[WARN]: Unable to access microphone. {error}")
|
||||||
|
self.stream = None
|
||||||
|
|
||||||
if host is not None and port is not None:
|
if host is not None and port is not None:
|
||||||
socket_url = f"ws://{host}:{port}"
|
socket_url = f"ws://{host}:{port}"
|
||||||
|
|||||||
Reference in New Issue
Block a user