-
Notifications
You must be signed in to change notification settings - Fork 0
Developing Whisper Service
Bennett Wu edited this page Sep 24, 2025
·
7 revisions
Core Technologies
- FastAPI: https://fastapi.tiangolo.com/
- Python: https://docs.python.org/3/
Tools
- Git: https://git-scm.com/
- Github Actions: https://docs.github.com/en/actions
- Pip: https://pip.pypa.io/en/stable/installation/
- Pylint: https://docs.pylint.org/
- Pytest: https://docs.pytest.org/en/stable/
Other
- PEP-8 Style Guide: https://peps.python.org/pep-0008/
- Ensure Python an pip are installed on your computer.
- Download from: https://www.python.org/
- Node: Whisper service was developed with Python 3.12 and up in mind.
- Python comes with pip, which we will use for managing our dependencies.
- The commands
python --versionandpip --versionwill return the version numbers of Python and pip respectively.- Make sure both commands run successfully. If they don't, make sure Python and pip are in your system path configuration.
- Download from: https://www.python.org/
- Ensure Git is installed on your computer. See: https://git-scm.com/
- Clone the repository
git clone https://github.com/scribear/ScribeAR-NodeServer - Move into the
whisper-servicedirectorycd ./ScribeAR-NodeServer/whisper-service - (Optional but recommended) Create a python virtual environment
- https://docs.python.org/3/library/venv.html
- Create the environment in folder called
.venvpython -m venv .venv - Activate the virtual environment
- POSIX systems (e.g. Linux, MacOS)
- bash/zsh (probably what you are using)
source .venv/bin/activate - fish
source .venv/bin/activate.fish - csh/tcsh
source .venv/bin/activate.csh - pwsh
.venv/bin/Activate.ps1
- bash/zsh (probably what you are using)
- Windows
- cmd.exe
.venv\Scripts\activate.bat
- PowerShell
.venv\Scripts\Activate.ps1
- cmd.exe
- POSIX systems (e.g. Linux, MacOS)
- Install dependencies
pip install -r requirements.txt - Make a copy of
template.envand name it.env - Make a copy of
device_config.template.jsonand name itdevice_config.json - Edit
.envanddevice_config.jsonto configure whisper service.- The templates already contain sensible defaults. A good place to start is to leave every thing except
API_KEYdefault. - See Configuring Whisper Service for details about each option.
- The templates already contain sensible defaults. A good place to start is to leave every thing except
- Start up your local instance. This will start the development server and automatically restart the app when you make changes.
python index.py --dev
Whisper service is unit tested using Pytest. These are used to check that individual components are working as expected in isolation.
- To run tests without code coverage
pytest - To run tests with code coverage. Coverage results can be found in
htmlcovfolder, you can open the.htmlfiles in your browser to see the coverage report.pytest --cov=. --cov-report=html - To create new tests, create file ending with
_test.pyin the same folder as the function/object you want to test.- The names of the test file should correspond to the name of the file containing the thing you are testing.
- Try to avoid writing tests that involve multiple files. If you find yourself doing so, it might be a sign that the scope of your function is too big.
- See https://docs.pytest.org/en/stable/ to learn how to use Pytest
- The names of the test file should correspond to the name of the file containing the thing you are testing.
Whisper service uses Pylint to ensure a consistent code style. Pylint uses the PEP-8 Style Guide (https://peps.python.org/pep-0008/).
- Run linter for a single file:
pylint [path_to_file] - Run linter for all
.pyfilespylint ./**/*.py *.py
- Ensure you have Docker installed. See: https://www.docker.com/
- Build container
- For CPU only container
docker build -t scribear-whisper-service -f ./Dockerfile_CPU . - For CUDA support
docker build -t scribear-whisper-service-cuda -f ./Dockerfile_CUDA .
- For CPU only container
- Make a copy of
template.envand name it.env - Edit
.envto configure container. See Configuring Docker Containers for details. - Run container (listens on port
8000)- For CPU only container
docker run --env-file .env -p 8000:80 whisper-service:latest - For CUDA support
docker run --env-file .env -p 8000:80 --gpus all whisper-service-cuda:latest
- For CPU only container
When modifying dependencies:
- Ensure that the new dependency is added to
requirements.txtand that changes are committed to Git.
Whisper service is designed to be extendable to use multiple transcription backends. Here are the steps for implementing a new backend.
- Implement
TranscriptionModelBasefound inmodel_bases/transcription_model_base.py- This can be achieved by directly implementing
TranscriptionModelBaseor by implementing any of children classes defined inmodel_bases/. These children classes implement commonly used methods and patterns to make development easier. - See Transcription Model Bases for documentation about implementing these.
- This can be achieved by directly implementing
- Add python dependencies for your model to
requirements.txt. - Associate an unique
implementation_idto your implementation.- Create a new
ModelImplementationIdenum for yourimplementation_idincustom_types/config_types.py - Update
import_model_implementation()functionmodel_implementations/import_model_implementations.pyto make a mapping to return your implementation
- Create a new
- Update documentation Model Implementations and Configuration to include your model.
-
app_config/-
load_config.py- This function loads the
.envfile and returns theAppConfigobject.
- This function loads the
-
model_factory.py- This function takes instantiates a model instance corresponding to the model key defined in
DeviceConfig. - Returns the instantiated model instance.
- This function takes instantiates a model instance corresponding to the model key defined in
-
-
custom_types/- Contains type hint definitions for objects used throughout the applications
-
model_bases/- Contains the transcription model base implementations.
- These do not provide transcriptions, but provide an interface and common methods for developing a transcription model.
- See Transcription Model Bases to learn about these.
-
model_implementations/- Contains implementations of transcription models.
- These do the hard work to provide transcriptions.
-
import_model_implementations.py- Defines the mappings from implementation id to model implementation.
- Also defines a function to dynamically import model implementation by implementation id.
-
server/- Contains files related to defining FastAPI webserver
-
helpers/- Contains helper functions for FastAPI server
-
create_server.py- Defines the FastAPI server
-
utils/- Contains utility functions.
-
.dockerignore- Defines files to be excluded in Docker image
- https://docs.docker.com/reference/dockerfile/#dockerignore-file
-
.gitignore- Defines files to be excluded from Git tracking
- https://git-scm.com/docs/gitignore
-
create_server.py- This function takes in the app configuration object and returns a FastAPI instance.
- The
/healthcheckand/whisperroutes are defined here.
-
Dockerfile_CPU- Defines the Docker image for whisper service
- https://docs.docker.com/reference/dockerfile/
-
Dockerfile_CUDA- Defines the Docker image with CUDA GPU support for whisper service
- https://docs.docker.com/reference/dockerfile/
-
index.py- This is the entrypoint into our application, the first thing that is run.
- It loads the configuration, creates the FastAPI server, and starts the server.
-
requirements.txt- Defines dependencies for pip.
- https://pip.pypa.io/en/stable/reference/requirements-file-format/
-
template.env- Contains a template version of the
.envfile used to configure the app - See Configuring Whisper Service for details
- Contains a template version of the
The Github Actions definitions for node server can be found in .github/workflows/whisper-service-ci.yml.
- Triggers:
- On demand
- Pull request
- Push to the
mainorstagingbranch containing changes to thewhisper-servicefolder
- https://docs.github.com/en/actions
The following jobs are defined:
-
test-lint-whisper-service- Runs
pytest,pylint --disable=import-error $(git ls-files '*.py')to ensure that code passes unit tests and has no code style errors. - If any of these commands fail, the job is failed.
- Runs
-
build-cpu-container-whisper-service- Builds the
scribear-whisper-service-cpuDocker container and pushes to Dockerhub - Images are tagged with pull request id, branch, and Github tags.
- Runs after
test-lint-whisper-servicefinishes successfully
- Builds the
-
build-cuda-container-whisper-service- Builds the
scribear-whisper-service-cpuDocker container and pushes to Dockerhub - Images are tagged with pull request id, branch, and Github tags.
- Runs after
test-lint-whisper-servicefinishes successfully
- Builds the
Additional documentation can be found in Documentation.