A simple Telegram bot that replies to voice messages with their transcription.
The project is split into a Whisper server (./python
) and
the telegram bot (./rust
).
- Python 3.10
- CUDA version 12
- WSL (if on Windows)
- Create a Python virtual environment:
python -m venv name_of_your_venv
- Activate the virtual environment
source name_of_your_venv/bin/activate
- Install the requirements:
pip install -r requirements.txt
You can run
python test_transcription.py
To test whether everything has been installed correctly. The output should be plain text.
The API used to receive and respond to requests is FastAPI and the server can be run using Uvicorn:
uvicorn main:app
By default, the port it will receive requests on is 8000
. You will also need to forward this port and set a static IP.
An alternative would be to configure ngrok.
If you want to test changes to the code whilst running the bot, add --reload
at the end of the command.
Create a ./rust/.env
file and fill in the following parameters:
TELOXIDE_TOKEN
: The Telegram bot tokenCHAT_IDS
: A comma delimited list of whitelisted chat ids. Here's a thread on how to get thoseWHISPER_URL
: The URL of the Whisper serverRUST_LOG
(optional): Use this to configure logging. I have it set toRUST_LOG=info,telegram_transcriber=debug
butRUST_LOG=info
is probably enough for you.
This is just another Rust project so you can just cargo run
. I wanted to run this on my Raspberry
Pi and just to save you a few headaches, if you only connect to your Pi via SSH, try running it with
nohup cargo r -r &
, this will run it in the background even after you disconnect from the SSH
session and all the logs will be dumped in ./rust/nohup.out
.
We are running the bot on a Raspberry Pi which takes sometime to compile (especially on release).
OpenSSL always causes some issues with cross compilation but thankfully,
cargo cross
helps with that. We opted to solve the issue by
optionally statically compiling OpenSSL into the binary which you can do with the following:
$ cross build --target aarch64-unknown-linux-gnu -r -F openssl-vendored
This is admitedly not very fast but it is faster. If you really want you can check out this to link it dynamically instead, just know you might need to fiddle with your apt sources or build some libs from source.