-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conversation mode, mic input, eos token for faster chat, debug comman…
…d, redo command, output streaming
- Loading branch information
1 parent
bb52d51
commit 2c2aed9
Showing
7 changed files
with
301 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
import sys | ||
from contextlib import contextmanager | ||
from whisper_mic import WhisperMic, get_logger | ||
|
||
# Hide error output from ALSA, JACK... (pyaudio) | ||
@contextmanager | ||
def ignoreStderr(): | ||
devnull = os.open(os.devnull, os.O_WRONLY) | ||
old_stderr = os.dup(2) | ||
sys.stderr.flush() | ||
os.dup2(devnull, 2) | ||
os.close(devnull) | ||
try: | ||
yield | ||
finally: | ||
os.dup2(old_stderr, 2) | ||
os.close(old_stderr) | ||
|
||
# custom WhisperMic for various fixes | ||
class CustomMic(WhisperMic): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.logger = get_logger('whisper_mic', level='warning') | ||
self.audio_model.to('cpu') | ||
|
||
def listen(self, timeout=None, phrase_time_limit=None): | ||
self.logger.info("Listening...") | ||
while self.result_queue.empty(): | ||
self._WhisperMic__listen_handler(timeout, phrase_time_limit) | ||
if self.result_queue.empty(): | ||
print('Too quiet, please repeat') | ||
while True: | ||
if not self.result_queue.empty(): | ||
return self.result_queue.get() | ||
|
||
# init mic | ||
with ignoreStderr(): | ||
mic = CustomMic(english=True, device='cuda') | ||
|
||
def listen(): | ||
print('\n> Listening (ctrl+c for menu)') | ||
with ignoreStderr(): | ||
mic.audio_model.to('cuda') | ||
result = None | ||
while not result: | ||
result = mic.listen() | ||
mic.audio_model.to('cpu') | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.