NetworkMonitorKokoro is a Flask-based service that provides advanced text-to-speech (T2S) and speech-to-text (S2T) functionalities using multiple model backends:
This repository leverages ONNX for efficient inference and Hugging Face's model hub for seamless model downloads.
You can see the script in action with the Quantum Network Monitor Assistant at https://freenetworkmonitor.click.
T2S (Text-to-Speech)
KOKORO_ONNX_MODE=legacy or stts2).KOKORO_ONNX_MODE=piper) for models like HAL-9000.S2T (Speech-to-Text)
Automatic Model Management
Flask API Endpoints
/generate_audio: Convert text into speech and cache by text hash./transcribe_audio: Transcribe uploaded audio; auto-converts to 16kHz WAV via ffmpeg./files/<filename>: Serve generated .wav files from the serve directory.Ensure you have the following installed:
python3 --version or python --version)pip --version)sudo apt-get install libsndfile1 espeak-ng
Clone the repository:
git clone https://github.com/yourusername/NetworkMonitorKokoro.git
cd NetworkMonitorKokoro
Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
python3 -m venv venv
venv\Scripts\activate
Once activated, you should see (venv) at the start of your command prompt, indicating the virtual environment is active.
Install dependencies (choose one path):
./install.sh
install.sh are already present on the machine (espeak, libsndfile1, ffmpeg, curl, tar on Linux).cd ~/code/services/kokoro
python3 -m venv venv
source venv/bin/activate
python3 install_dependencies.py
Set up the models:
campwill/HAL-9000-Piper-TTS) if missing.Install Piper runtime if using KOKORO_ONNX_MODE=piper:
install.sh prompts to install Piper globally on Linux.PIPER_BIN (default expected path: /usr/local/bin/piper).Configure file serving directory (optional):
./files.export SERVE_DIR=/absolute/path/for/generated/audio
mkdir -p "$SERVE_DIR"
Start the Flask server directly:
python3 app.py
Deactivate the virtual environment (optional):
deactivate
To run NetworkMonitorKokoro as a systemd service on Linux, follow these steps:
Clone the repository:
git clone https://github.com/yourusername/NetworkMonitorKokoro.git
cd NetworkMonitorKokoro
Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
Install dependencies:
python3 install_dependencies.py
Create a systemd service file:
sudo nano /etc/systemd/system/networkmonitor-kokoro.service
Add the following content:
[Unit]
Description=NetworkMonitorKokoro Service
After=network.target
[Service]
User=yourusername
WorkingDirectory=/path/to/NetworkMonitorKokoro
ExecStart=/path/to/NetworkMonitorKokoro/venv/bin/python3 /path/to/NetworkMonitorKokoro/app.py
Restart=always
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target
Replace /path/to/NetworkMonitorKokoro with the full path to the directory where the repository was cloned and the virtual environment was created. Replace yourusername with your Linux username.
Set proper permissions:
sudo chmod 644 /etc/systemd/system/networkmonitor-kokoro.service
Reload systemd:
sudo systemctl daemon-reload
Start the service:
sudo systemctl start networkmonitor-kokoro
Enable the service to start on boot:
sudo systemctl enable networkmonitor-kokoro
Check the service status:
sudo systemctl status networkmonitor-kokoro
/generate_audioPOSTtext (string, required): text to synthesize. Max 1024 chars. Input is preprocessed and hashed for caching.{ "text": "Your text here" }
{
"status": "success",
"filename": "<sha256(text)>.wav"
}
$SERVE_DIR or ./files).GET /files/<filename>./transcribe_audioPOSTmultipart/form-data with file field name file.ffmpeg and applies light denoise/normalization filters.{
"status": "success",
"transcription": "Your transcription here"
}
Engine selection:
whisper_pt).USE_WAV2VEC2=1 to use the ONNX Wav2Vec2 pipeline.ASR_ENGINE=wav2vec2_onnx or ASR_ENGINE=whisper_pt.Wav2Vec2 model selection:
facebook/wav2vec2-base-960hASR_MODEL_NAME if you want a different Wav2Vec2 model.Wav2Vec2 ONNX model provisioning:
ASR_ONNX_PATH does not exist, the app downloads a ready-made ONNX model from ASR_ONNX_REPO and stores it under asr_onnx/<model_name>.onnx.ASR_ONNX_REPO=onnx-community/wav2vec2-base-960h-ONNXASR_ONNX_REPO or the destination path via ASR_ONNX_PATH.input_values (batch, samples) float32 at 16 kHz and output CTC logits (batch, time, vocab).Wav2Vec2Processor from the matching Facebook model for feature extraction and decoding.Optional punctuation restoration:
PUNCTUATE_TEXT=1 (default off).PUNCTUATION_MODEL=kredor/punctuate-all.Optional tech normalization:
TECH_NORMALIZE=1 (default off).Example run with Wav2Vec2 ONNX:
export USE_WAV2VEC2=1
# optional: override processor/model or ONNX repo/path
# export ASR_MODEL_NAME=facebook/wav2vec2-base-960h
# optional override of the source repo or ONNX path
# export ASR_ONNX_REPO=onnx-community/wav2vec2-base-960h-ONNX
# export ASR_ONNX_PATH=asr_onnx/custom.onnx
# optional: post-processing
# export PUNCTUATE_TEXT=1
# export TECH_NORMALIZE=1
python3 app.py
Example run with Whisper fallback:
# default is whisper, so no flags needed
python3 app.py
KOKORO_ONNX_MODE=auto (default):
legacy or stts2.KOKORO_ONNX_MODE=legacy:
input_ids, style, speed) and voice .bin vectors.KOKORO_ONNX_MODE=stts2:
input/input_lengths, optional ids/sid, optional scales).KOKORO_ONNX_MODE=piper:
PIPER_BIN, default piper).PIPER_MODEL_PATH and PIPER_CONFIG_PATH.export KOKORO_ONNX_MODE=legacy
python3 app.py
export KOKORO_ONNX_MODE=piper
export PIPER_BIN=/usr/local/bin/piper
export PIPER_MODEL_PATH=kokoro_model/onnx/model.onnx
export PIPER_CONFIG_PATH=kokoro_model/onnx/model.onnx.json
python3 app.py
/files/<filename>GET.wav files located in the serve directory.MAX_THREADS=2).onnx-community/Kokoro-82M-v1.0-ONNXcampwill/HAL-9000-Piper-TTSUSE_WAV2VEC2=1.MODEL_INIT_MODE=lazy): TTS assets load on first /generate_audio, ASR assets load on first /transcribe_audio.MODEL_INIT_MODE=startup to preload everything at app start.$SERVE_DIR (default ./files).Generate audio:
curl -sX POST http://localhost:7860/generate_audio \
-H 'Content-Type: application/json' \
-d '{"text":"Hello from Kokoro."}'
# => {"status":"success","filename":"<hash>.wav"}
curl -O http://localhost:7860/files/<hash>.wav
Transcribe audio:
curl -sX POST http://localhost:7860/transcribe_audio \
-F file=@sample.webm
# => {"status":"success","transcription":"..."}
curl -sX POST \
-H "Content-Type: application/json" \
-d '{"text":"Hello, world!"}' \
http://127.0.0.1:7860/generate_audio
curl -sX POST \
-F "file=@sample_audio.wav" \
http://127.0.0.1:7860/transcribe_audio
Contributions are welcome! Please follow these steps:
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or support, please open an issue or contact support@mahadeva.co.uk.
Python
95.7%
Shell
4.3%
NetworkMonitorKokoro is a Flask-based service that provides advanced text-to-speech (T2S) and speech-to-text (S2T) functionalities using multiple model backends:
This repository leverages ONNX for efficient inference and Hugging Face's model hub for seamless model downloads.
You can see the script in action with the Quantum Network Monitor Assistant at https://freenetworkmonitor.click.
T2S (Text-to-Speech)
KOKORO_ONNX_MODE=legacy or stts2).KOKORO_ONNX_MODE=piper) for models like HAL-9000.S2T (Speech-to-Text)
Automatic Model Management
Flask API Endpoints
/generate_audio: Convert text into speech and cache by text hash./transcribe_audio: Transcribe uploaded audio; auto-converts to 16kHz WAV via ffmpeg./files/<filename>: Serve generated .wav files from the serve directory.Ensure you have the following installed:
python3 --version or python --version)pip --version)sudo apt-get install libsndfile1 espeak-ng
Clone the repository:
git clone https://github.com/yourusername/NetworkMonitorKokoro.git
cd NetworkMonitorKokoro
Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
python3 -m venv venv
venv\Scripts\activate
Once activated, you should see (venv) at the start of your command prompt, indicating the virtual environment is active.
Install dependencies (choose one path):
./install.sh
install.sh are already present on the machine (espeak, libsndfile1, ffmpeg, curl, tar on Linux).cd ~/code/services/kokoro
python3 -m venv venv
source venv/bin/activate
python3 install_dependencies.py
Set up the models:
campwill/HAL-9000-Piper-TTS) if missing.Install Piper runtime if using KOKORO_ONNX_MODE=piper:
install.sh prompts to install Piper globally on Linux.PIPER_BIN (default expected path: /usr/local/bin/piper).Configure file serving directory (optional):
./files.export SERVE_DIR=/absolute/path/for/generated/audio
mkdir -p "$SERVE_DIR"
Start the Flask server directly:
python3 app.py
Deactivate the virtual environment (optional):
deactivate
To run NetworkMonitorKokoro as a systemd service on Linux, follow these steps:
Clone the repository:
git clone https://github.com/yourusername/NetworkMonitorKokoro.git
cd NetworkMonitorKokoro
Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
Install dependencies:
python3 install_dependencies.py
Create a systemd service file:
sudo nano /etc/systemd/system/networkmonitor-kokoro.service
Add the following content:
[Unit]
Description=NetworkMonitorKokoro Service
After=network.target
[Service]
User=yourusername
WorkingDirectory=/path/to/NetworkMonitorKokoro
ExecStart=/path/to/NetworkMonitorKokoro/venv/bin/python3 /path/to/NetworkMonitorKokoro/app.py
Restart=always
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.target
Replace /path/to/NetworkMonitorKokoro with the full path to the directory where the repository was cloned and the virtual environment was created. Replace yourusername with your Linux username.
Set proper permissions:
sudo chmod 644 /etc/systemd/system/networkmonitor-kokoro.service
Reload systemd:
sudo systemctl daemon-reload
Start the service:
sudo systemctl start networkmonitor-kokoro
Enable the service to start on boot:
sudo systemctl enable networkmonitor-kokoro
Check the service status:
sudo systemctl status networkmonitor-kokoro
/generate_audioPOSTtext (string, required): text to synthesize. Max 1024 chars. Input is preprocessed and hashed for caching.{ "text": "Your text here" }
{
"status": "success",
"filename": "<sha256(text)>.wav"
}
$SERVE_DIR or ./files).GET /files/<filename>./transcribe_audioPOSTmultipart/form-data with file field name file.ffmpeg and applies light denoise/normalization filters.{
"status": "success",
"transcription": "Your transcription here"
}
Engine selection:
whisper_pt).USE_WAV2VEC2=1 to use the ONNX Wav2Vec2 pipeline.ASR_ENGINE=wav2vec2_onnx or ASR_ENGINE=whisper_pt.Wav2Vec2 model selection:
facebook/wav2vec2-base-960hASR_MODEL_NAME if you want a different Wav2Vec2 model.Wav2Vec2 ONNX model provisioning:
ASR_ONNX_PATH does not exist, the app downloads a ready-made ONNX model from ASR_ONNX_REPO and stores it under asr_onnx/<model_name>.onnx.ASR_ONNX_REPO=onnx-community/wav2vec2-base-960h-ONNXASR_ONNX_REPO or the destination path via ASR_ONNX_PATH.input_values (batch, samples) float32 at 16 kHz and output CTC logits (batch, time, vocab).Wav2Vec2Processor from the matching Facebook model for feature extraction and decoding.Optional punctuation restoration:
PUNCTUATE_TEXT=1 (default off).PUNCTUATION_MODEL=kredor/punctuate-all.Optional tech normalization:
TECH_NORMALIZE=1 (default off).Example run with Wav2Vec2 ONNX:
export USE_WAV2VEC2=1
# optional: override processor/model or ONNX repo/path
# export ASR_MODEL_NAME=facebook/wav2vec2-base-960h
# optional override of the source repo or ONNX path
# export ASR_ONNX_REPO=onnx-community/wav2vec2-base-960h-ONNX
# export ASR_ONNX_PATH=asr_onnx/custom.onnx
# optional: post-processing
# export PUNCTUATE_TEXT=1
# export TECH_NORMALIZE=1
python3 app.py
Example run with Whisper fallback:
# default is whisper, so no flags needed
python3 app.py
KOKORO_ONNX_MODE=auto (default):
legacy or stts2.KOKORO_ONNX_MODE=legacy:
input_ids, style, speed) and voice .bin vectors.KOKORO_ONNX_MODE=stts2:
input/input_lengths, optional ids/sid, optional scales).KOKORO_ONNX_MODE=piper:
PIPER_BIN, default piper).PIPER_MODEL_PATH and PIPER_CONFIG_PATH.export KOKORO_ONNX_MODE=legacy
python3 app.py
export KOKORO_ONNX_MODE=piper
export PIPER_BIN=/usr/local/bin/piper
export PIPER_MODEL_PATH=kokoro_model/onnx/model.onnx
export PIPER_CONFIG_PATH=kokoro_model/onnx/model.onnx.json
python3 app.py
/files/<filename>GET.wav files located in the serve directory.MAX_THREADS=2).onnx-community/Kokoro-82M-v1.0-ONNXcampwill/HAL-9000-Piper-TTSUSE_WAV2VEC2=1.MODEL_INIT_MODE=lazy): TTS assets load on first /generate_audio, ASR assets load on first /transcribe_audio.MODEL_INIT_MODE=startup to preload everything at app start.$SERVE_DIR (default ./files).Generate audio:
curl -sX POST http://localhost:7860/generate_audio \
-H 'Content-Type: application/json' \
-d '{"text":"Hello from Kokoro."}'
# => {"status":"success","filename":"<hash>.wav"}
curl -O http://localhost:7860/files/<hash>.wav
Transcribe audio:
curl -sX POST http://localhost:7860/transcribe_audio \
-F file=@sample.webm
# => {"status":"success","transcription":"..."}
curl -sX POST \
-H "Content-Type: application/json" \
-d '{"text":"Hello, world!"}' \
http://127.0.0.1:7860/generate_audio
curl -sX POST \
-F "file=@sample_audio.wav" \
http://127.0.0.1:7860/transcribe_audio
Contributions are welcome! Please follow these steps:
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or support, please open an issue or contact support@mahadeva.co.uk.
Python
95.7%
Shell
4.3%