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
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
default_language_version:
python: python3.11

repos:
# mypy checks type annotations.
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
args: [--config-file=pyproject.toml]

# pre-commit-hooks is a collection of Git hooks for code quality, formatting, and analysis.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-toml
- id: debug-statements

# An extremely fast Python linter and code formatter, written in Rust.
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.4.5
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Whisper Mic

This repo is based on the work done [here](https://github.com/openai/whisper) by OpenAI. This repo allows you use use a mic as demo. This repo copies some of the README from the original project.

## Video Tutorial
Expand All @@ -20,8 +21,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 All @@ -35,13 +35,15 @@ For English-only applications, the `.en` models tend to perform better, especial

## Microphone Demo

You can use the model with a microphone using the ```whisper_mic``` program. Use ```-h``` to see flag options.
You can use the model with a microphone using the ```whisper_mic``` program. Use ```--help``` to see flag options.

> Example: ```python -m whisper_mic --help```

Some of the more important flags are the ```--model``` and ```--english``` flags.

## Transcribing To A File

Using the command: ```whisper_mic --loop --dictate``` will type the words you say on your active cursor.
Using the command: ```python -m whisper_mic --loop --dictate``` will type the words you say on your active cursor.

## Usage In Other Projects

Expand All @@ -60,22 +62,27 @@ Check out what the possible arguments are by looking at the ```cli.py``` file
## Troubleshooting

If you are having issues, try the following:
```

```bash
sudo apt install portaudio19-dev python3-pyaudio
```

## Contributing

Some ideas that you can add are:

1. Supporting different implementations of Whisper
2. Adding additional optional functionality.
3. Add tests

Be sure to run ```pre-commit install``` before making any changes and running it before committing with ```pre-commit run --all-files```.

## License

The model weights of Whisper are released under the MIT License. See their repo for more information.

This code under this repo is under the MIT license. See [LICENSE](LICENSE) for further details.

## Thanks

Until recently, access to high performing speech to text models was only available through paid serviecs. With this release, I am excited for the many applications that will come.
153 changes: 126 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,40 +1,139 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
[tool.poetry]
name = "whisper_mic"
version = "1.4.2"
authors = [
{ name="Blake Mallory", email="blakecmallory@gmail.com" },
"Blake Mallory <blakecmallory@gmail.com>",
]
description = "Whisper for your microphone"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
'importlib-metadata; python_version>"3.9"',
"attrs",
"click",
"ffmpeg-python",
"more-itertools",
"numpy",
"openai-whisper",
"pyaudio",
"pydantic",
"pydub",
"pynput",
"requests",
"rich",
"speechrecognition",
"tdqm",
"torch",
"transformers",
]

[project.scripts]
[tool.poetry.dependencies]
python = "^3.11.0"

click = "^8.1.7"
ffmpeg-python= "0.2.0"
more-itertools = "^10.2.0"
numpy = "^1.26.4"
openai-whisper = "^20231117"
pyaudio = "^0.2.14"
pydub = "^0.25.1"
pynput = "^1.7.6"
rich = "^13.7.1"
speechrecognition = "^3.10.4"
tqdm = "^4.66.4"
torch = "^2.3.0"
transformers = "^4.40.2"

[tool.poetry.group.dev.dependencies]
mypy = "1.10.0"
pre-commit = "3.7.1"
pre-commit-hooks = "4.6.0"
ruff = "0.4.5"

[tool.poetry.scripts]
whisper_mic = "whisper_mic.cli:main"

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.mypy]
python_version = "3.11"

check_untyped_defs = true
disallow_untyped_defs = true
incremental = false
ignore_errors = false
pretty = true
show_error_context = true
show_traceback = true
strict_optional = true
warn_incomplete_stub = true
warn_no_return = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = [
"click.*",
"faster_whisper.*",
"numpy.*",
"pynput.*",
"rich.*",
"speech_recognition.*",
"torch.*",
"whisper.*",
]
ignore_missing_imports = true

[tool.ruff]
target-version = "py311"

exclude = ["alembic"]
indent-width = 4
line-length = 110

[tool.ruff.lint]
# rules from: https://docs.astral.sh/ruff/rules/
select = [
"ANN", # flake8-annotations
"ASYNC", # flake8-async
"S", # flake8-bandit
"B", # flake8-bugbear
"A", # flake8-builtins
"COM", # flake8-commas
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"EM", # flake8-errmsg
"LOG", # flake8-logging
"G", # flake8-logging-format
"PIE", # flake8-pie
"T20", # flake8-print
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"ARG", # flake8-unused-arguments
"I", # isort
"N", # pep8-naming
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"UP", # pyupgrade
"RUF", # Ruff-specific rules
"TRY", # tryceratops
]
ignore = [
"ANN101", # Missing type annotation for `self` in method
"B008", # Do not perform function calls in argument defaults
"E501", # Line too long, handled by black
"G004", # Logging statements should not use f"..."
"W191", # Indentation contains tabs
]
fixable = ["ALL"]
unfixable = []
# logger-objects = ["logging_setup.logger"] # TODO: test first

[tool.ruff.format]
line-ending = "auto"
quote-style = "double"
skip-magic-trailing-comma = false

[tool.ruff.lint.isort]
# force-sort-within-sections = true # TODO: test first
lines-after-imports = 2
lines-between-types = 1

[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true
13 changes: 0 additions & 13 deletions requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions whisper_mic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
from .whisper_mic import *
from .utils import *
5 changes: 5 additions & 0 deletions whisper_mic/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from whisper_mic.cli import main


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