Skip to content

AntoniosBarotsis/telegram-transcriber

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Transcriber Bot

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).

The Whisper Server

Dependencies

  • Python 3.10
  • CUDA version 12
  • WSL (if on Windows)

Configuration

  1. Create a Python virtual environment:
python -m venv name_of_your_venv
  1. Activate the virtual environment
source name_of_your_venv/bin/activate
  1. Install the requirements:
pip install -r requirements.txt

Testing if Whisper can run

You can run

python test_transcription.py

To test whether everything has been installed correctly. The output should be plain text.

Running

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.

The Telegram Bot

Dependencies

Configuration

Create a ./rust/.env file and fill in the following parameters:

  • TELOXIDE_TOKEN: The Telegram bot token
  • CHAT_IDS: A comma delimited list of whitelisted chat ids. Here's a thread on how to get those
  • WHISPER_URL: The URL of the Whisper server
  • RUST_LOG (optional): Use this to configure logging. I have it set to RUST_LOG=info,telegram_transcriber=debug but RUST_LOG=info is probably enough for you.

Running

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.

Cross Compiling

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.