Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions whisper_mic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
@click.option("--list_devices",default=False, help="Flag to list devices", is_flag=True,type=bool)
@click.option("--faster",default=False, help="Use faster_whisper implementation", is_flag=True,type=bool)
@click.option("--hallucinate_threshold",default=400, help="Raise this to reduce hallucinations. Lower this to activate more often.", is_flag=False,type=int)
def main(model: str, english: bool, verbose: bool, energy: int, pause: float, dynamic_energy: bool, save_file: bool, device: str, loop: bool, dictate: bool,mic_index:Optional[int],list_devices: bool,faster: bool,hallucinate_threshold:int) -> None:
@click.option("--language",default=None, help="The language to use", type=str)
def main(model: str, english: bool, verbose: bool, energy: int, pause: float, dynamic_energy: bool, save_file: bool, device: str, loop: bool, dictate: bool,mic_index:Optional[int],list_devices: bool,faster: bool,hallucinate_threshold:int,language: str) -> None:
if list_devices:
print("Possible devices: ",sr.Microphone.list_microphone_names())
return
mic = WhisperMic(model=model, english=english, verbose=verbose, energy=energy, pause=pause, dynamic_energy=dynamic_energy, save_file=save_file, device=device,mic_index=mic_index,implementation=("faster_whisper" if faster else "whisper"),hallucinate_threshold=hallucinate_threshold)
mic = WhisperMic(model=model, english=english, verbose=verbose, energy=energy, pause=pause, dynamic_energy=dynamic_energy, save_file=save_file, device=device,mic_index=mic_index,implementation=("faster_whisper" if faster else "whisper"),hallucinate_threshold=hallucinate_threshold,language=language)

if not loop:
try:
Expand Down
5 changes: 3 additions & 2 deletions whisper_mic/whisper_mic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# asound = cdll.LoadLibrary('libasound.so')
# asound.snd_lib_error_set_handler(c_error_handler)
class WhisperMic:
def __init__(self,model="base",device=("cuda" if torch.cuda.is_available() else "cpu"),english=False,verbose=False,energy=300,pause=2,dynamic_energy=False,save_file=False, model_root="~/.cache/whisper",mic_index=None,implementation="whisper",hallucinate_threshold=300):
def __init__(self,model="base",device=("cuda" if torch.cuda.is_available() else "cpu"),english=False,verbose=False,energy=300,pause=2,dynamic_energy=False,save_file=False, model_root="~/.cache/whisper",mic_index=None,implementation="whisper",hallucinate_threshold=300,language=None):

self.logger = get_logger("whisper_mic", "info")
self.energy = energy
Expand All @@ -35,6 +35,7 @@ def __init__(self,model="base",device=("cuda" if torch.cuda.is_available() else
self.verbose = verbose
self.english = english
self.keyboard = pynput.keyboard.Controller()
self.language = 'english' if english else language

self.platform = platform.system().lower()
if self.platform == "darwin":
Expand Down Expand Up @@ -179,7 +180,7 @@ def __transcribe(self,data=None, realtime: bool = False) -> None:
if self.english:
result = self.audio_model.transcribe(audio_data,language='english',suppress_tokens="")
else:
result = self.audio_model.transcribe(audio_data,suppress_tokens="")
result = self.audio_model.transcribe(audio_data,language=self.language,suppress_tokens="")
predicted_text = result["text"]

if not self.verbose:
Expand Down