Skip to content

italankin/samplevoicebot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample Voice Bot

Telegram text-to-speech bot. It works in both inline and text mode and offers a convenient interface to generate voice from the text.

Try it out: @samplevoicebot.

Requirements

Bot requires an AWS account to work. It uses Amazon Polly to generate voice and S3 to store and share generated voice files.

Configuration

Bot is configured via environmental variables, listed in config.py.

The table below shows required parameters:

Parameter Description
TELEGRAM_BOT_TOKEN Token issued by @BotFather
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY AWS credentials
AWS_S3_BUCKET AWS bucket name where files will be stored
AWS_REGION_NAME AWS region name where your bucket is located e.g. us-east-1

Other parameters:

Parameter Values Default Description
TELEGRAM_ADMIN_ID int -1 User ID - admin of this bot
TELEGRAM_MIN_MESSAGE_LENGTH int 1 Minimal message length to generate voice
TELEGRAM_MAX_MESSAGE_LENGTH int 255 Maximum message length to generate voice (inline messages cannot exceed 256 characters)
TELEGRAM_INLINE_DEBOUNCE_MILLIS int 1000 Debounce interval for incoming inline requests to avoid unnecessary voice generations
LANGUAGE_DETECT_MAPPINGS str Language mappings in format from=to. Multiple substitutions can be joined with commas e.g. mk=ru,bg=ru,uk=ru
MAX_WORKERS int 4 A number of workers used for concurrent jobs (e.g. speech synthesis)
PREFETCH_LANGUAGES str List languages (e.g. ru,en) to prefetch voices list* on bot startup
VOICES str Specify voices to use, e.g. ru-RU=Tatyana,Maxim. Join multiple mappings with ;. List of supported voices
DEBUG 1, 0 0 Enable/disable verbose logging

* In inline mode bot uses only 2 voices per language to minimize synthesize requests

AWS configuration

An unrestricted, unauthorized public access to the objects in the bucket is required. This can be achieved with bucket policy:

Bucket policy
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicRead",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::samplebucket/*"
        }
    ]
}

* samplebucket must be substituted with your backet name.

See docs for more info.

Docker

Images

Images are available at ghcr.io.

Build image

$ docker build -t samplevoicebot .

Run image

Create a file named .env and put your credentials, for example:

AWS_ACCESS_KEY_ID=<your-aws-access-key-id>
AWS_SECRET_ACCESS_KEY=<your-aws-secret-access-key>
AWS_REGION_NAME=<aws-region-name>
AWS_S3_BUCKET=<your-s3-bucket-name>
TELEGRAM_BOT_TOKEN=<your-telegram-bot-token>
<any-additional-parameters>

Run:

$ docker run -d --env-file .env samplevoicebot