Merge pull request #173 from FlippFuzz/fix-os-error-no-mic

Handle failure on systems without microphones
This commit is contained in:
makaveli
2024-03-11 14:50:15 +05:30
committed by GitHub
+11 -7
View File
@@ -66,13 +66,17 @@ 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()
self.stream = self.p.open( try:
format=self.format, self.stream = self.p.open(
channels=self.channels, format=self.format,
rate=self.rate, channels=self.channels,
input=True, rate=self.rate,
frames_per_buffer=self.chunk, input=True,
) 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}"