Simple Telegram bot that converts voice messages to text using Google Speech. Can be found at @voicos_bot, but currently disabled, since Google won't accept my credit cards :')
- python-telegram-bot
- pymediainfo (and a system library libmediainfo)
- google-cloud-speech
- google-cloud-storage
- psycopg2-binary (and, well, PostgreSQL itself)
- Install the libraries via pip:
pip install -r requirements.txt
- Go to Google Cloud and set up a new project. You will need Google Speech API. For messages longer than 1 minute you will also need Google Storage
- Generate new service account and download a private key as JSON
- Set environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the file path of the JSON key (see here for more instructions) - Go to the Google Storage page and create a new bucket
- Message @BotFather on Telegram to create a new bot
- Set up
VOICOS_TOKEN
,VOICOS_BUCKET
andVOICOS_ADMIN_ID
environment variables - Set up PostgreSQL and change connection string in bot.py
- Run the bot
python3 bot.py
You will need to pass your credentials JSON to the container and to pass the environment variables with tokens and such.
With PostgreSQL already set up natively (please don't leave it with open ports, I will not responsible), your run command will look something like this:
docker run -d --restart unless-stopped --name voicos \
--mount type=bind,source=/path/to/credentials.json,target=/app/credentials.json,readonly \
--env-file voicos.env \
ghcr.io/graynk/voicos:latest
To use Postgre in container as well, put docker-compose.yml
, credentials.json
, voicos.env
, data
directory and your postgres.conf
in the same directory, then run:
sudo docker-compose up &
Hopefully you know what you're doing and can edit docker-compose.yml
if needed, because I don't have any desire to write a longer instruction than this.
Launch the bot, forward the voice message, easy. Works in group chats as well. For messages longer than 1 minute the bot uses long recognition with uploading to Google Storage