Skip to content

Commit

Permalink
Merge pull request #173 from FlippFuzz/fix-os-error-no-mic
Browse files Browse the repository at this point in the history
Handle failure on systems without microphones
  • Loading branch information
makaveli10 authored Mar 11, 2024
2 parents a17f404 + 4d477e3 commit ebd2dc9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions whisper_live/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ def __init__(
self.timestamp_offset = 0.0
self.audio_bytes = None
self.p = pyaudio.PyAudio()
self.stream = self.p.open(
format=self.format,
channels=self.channels,
rate=self.rate,
input=True,
frames_per_buffer=self.chunk,
)
try:
self.stream = self.p.open(
format=self.format,
channels=self.channels,
rate=self.rate,
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:
socket_url = f"ws://{host}:{port}"
Expand Down

0 comments on commit ebd2dc9

Please sign in to comment.