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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Now a pip package!

## Available models and languages

There are five model sizes, four with English-only versions, offering speed and accuracy tradeoffs. Below are the names of the available models and their approximate memory requirements and relative speed.
There are five model sizes, four with English-only versions, offering speed and accuracy tradeoffs. Below are the names of the available models and their approximate memory requirements and relative speed.


| Size | Parameters | English-only model | Multilingual model | Required VRAM | Relative speed |
Expand Down Expand Up @@ -63,6 +63,11 @@ If you are having issues, try the following:
```
sudo apt install portaudio19-dev python3-pyaudio
```
You'll also need the python3-dev for your specific python version...
example for python 3.10:
```
sudo apt-get install python3.10-dev
```

## Contributing

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
faster-whisper
numpy
tqdm
more-itertools
Expand Down
147 changes: 129 additions & 18 deletions whisper_mic/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
# flake8:noqa: E304

import click
import torch
Expand All @@ -7,26 +8,135 @@

from whisper_mic import WhisperMic


@click.command()
@click.option("--model", default="base", help="Model to use", type=click.Choice(["tiny","base", "small","medium","large","large-v2","large-v3"]))
@click.option("--device", default=("cuda" if torch.cuda.is_available() else "cpu"), help="Device to use", type=click.Choice(["cpu","cuda","mps"]))
@click.option("--english", default=False, help="Whether to use English model",is_flag=True, type=bool)
@click.option("--verbose", default=False, help="Whether to print verbose output", is_flag=True,type=bool)
@click.option("--energy", default=300, help="Energy level for mic to detect", type=int)
@click.option("--dynamic_energy", default=False,is_flag=True, help="Flag to enable dynamic energy", type=bool)
@click.option("--pause", default=0.8, help="Pause time before entry ends", type=float)
@click.option("--save_file",default=False, help="Flag to save file", is_flag=True,type=bool)
@click.option("--loop", default=False, help="Flag to loop", is_flag=True,type=bool)
@click.option("--dictate", default=False, help="Flag to dictate (implies loop)", is_flag=True,type=bool)
@click.option("--mic_index", default=None, help="Mic index to use", type=int)
@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(
"--model",
default="base",
help="Model to use",
type=click.Choice(["tiny", "base", "small", "medium", "large", "large-v2", "large-v3"]),)

@click.option(
"--device",
default=("cuda" if torch.cuda.is_available() else "cpu"),
help="Device to use",
type=click.Choice(["cpu", "cuda", "mps"]),)

@click.option(
"--english",
default=False,
help="Whether to use English model",
is_flag=True,
type=bool,)

@click.option(
"--verbose",
default=False,
help="Whether to print verbose output",
is_flag=True,
type=bool,)

@click.option(
"--energy",
default=300,
help="Energy level for mic to detect",
type=int,)

@click.option(
"--dynamic_energy",
default=False,
is_flag=True,
help="Flag to enable dynamic energy",
type=bool,)

@click.option(
"--pause",
default=0.8,
help="Pause time before entry ends",
type=float,)

@click.option(
"--save_file",
default=False,
help="Flag to save file",
is_flag=True,
type=bool,)

@click.option(
"--loop",
default=False,
help="Flag to loop",
is_flag=True,
type=bool,)

@click.option(
"--dictate",
default=False,
help="Flag to dictate (implies loop)",
is_flag=True,
type=bool,)

@click.option(
"--mic_index",
default=None,
help="Mic index to use",
type=int,)

@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:

if list_devices:
print("Possible devices: ",sr.Microphone.list_microphone_names())
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,)

if not loop:
try:
Expand All @@ -39,12 +149,13 @@ def main(model: str, english: bool, verbose: bool, energy: int, pause: float, d
mic.file.close()
else:
try:
mic.listen_loop(dictate=dictate,phrase_time_limit=2)
mic.listen_loop(dictate=dictate, phrase_time_limit=2)
except KeyboardInterrupt:
print("Operation interrupted successfully")
finally:
if save_file:
mic.file.close()


if __name__ == "__main__":
main()
Loading