Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*.*~
*.pyc
*.iml
*.txt
*.yml
!docker-compose.yml
!requirements.txt
data/*
analyze/*
bin/*
.idea/*
.handler-saves/*
notify_failure.sh
__pycache__/*
venv
.venv
txt2speech-venv/*
.vscode
.DS_Store
.python-version
.env
23 changes: 17 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
*.pyc
*.iml
*.txt
data/
analyze/
bin/
.idea/
.handler-saves/
notify_failure.sh
*.yml
!docker-compose.yml
!requirements.txt
data/*
analyze/*
bin/*
.idea/*
.handler-saves/*
notify_failure.sh
__pycache__/*
venv
.venv
txt2speech-venv/*
.vscode
.DS_Store
.python-version
.env
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.13-slim

WORKDIR /usr/src/app

RUN apt-get update && \
apt-get install -y --no-install-recommends \
libmagic1 libmagic-dev \
ffmpeg \
postgresql-client \
default-mysql-client && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

ENTRYPOINT ["./wait_for_db.sh"]
CMD ["python", "-m", "txt2SpeechBot"]
193 changes: 191 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,195 @@ They will appear every time you type the bot's name without any additional text.
If you would want to add an audio to this menu, don't hesitate to contact me on telegram ([@supremoh](https://t.me/supremoh)).
I will decide if it is suitable for the bot.

<br><br>
<br>

* This bot collects some data for its proper operation. If you use it, you're accepting this fact.
* This bot collects some data for its proper operation. If you use it, you're accepting this fact.
* You can delete any stored data with `/delete_my_data` command.
* You can view what data is collected with `/privacy` command.

---

## Local Setup

You can run this bot using Docker Compose with profiles or Docker-less.

### 1. Clone the Repository

```bash
git clone https://github.com/gmm96/Txt2SpeechBot.git
cd Txt2SpeechBot
```

### 2. Create and Configure `.env`

Open .env and modify it with your variables.

```bash
cp sample.env .env
```

<details>
<summary><strong>Configuration Variables</strong></summary>

### Bot Settings

* `BOT_TOKEN`: Your Telegram Bot token (required).
* `TTS_API`: Your Text-to-Speech API endpoint. (required).
* `HOST_PERSISTENT_PATH`: Absolute path on your host for storing files persistently (e.g. `/home/user/txt2speech`).
* `OWNER_ID`: Telegram user ID of the bot owner.
* `ADMINS_IDS`: Comma-separated list of Telegram user IDs with admin access.
* `ALLOWED_CHATS`: Comma-separated list of allowed chat or group IDs. Leave empty for global access.

### Usage Limits

* `MAX_AUDIO_SIZE`: Maximum audio file size in MB (default: 20).
* `MAX_STORED_AUDIO`: Maximum number of audios stored per user (default: 50).
* `MAX_CHARACTER_DESC`: Max characters allowed in audio description (default: 30).
* `MAX_CHARACTER_QUERY`: Max characters allowed per TTS query (default: 200).

### Logging & Error Handling

* `FORWARD_ERRORS_TO_OWNER`: `bool` forward exceptions to `OWNER_ID`.
* `SAVE_INPUT_MSG`: `bool` save incoming messages to `messages.log`.
* `SAVE_INPUT_QUERIES`: `bool` save text queries to `queries.log`.
* `SAVE_UNAUTHORIZED`: `bool` log unauthorized access attempts.

### Database Settings

* `DB_TYPE`: One of `postgresql`, `mysql`, `mariadb`, or `sqlite`.
* `DB_NAME`, `DB_USERNAME`, `DB_PASSWORD`: Credentials used for the selected database.
* `DB_PATH`: Hostname or file path depending on DB type (e.g. `postgresql-db` (for Docker) or `db.myhost.com` (for external) or `data/db.sqlite` for SQLite).
* `DB_PORT`: Port used by the database (e.g. 5432 for PostgreSQL).
* `DB_ROOT_PASSWORD`: Database root password (Only for MySQL/MariaDB).

### Admin Interfaces

* `DB_MANAGER_EXTERNAL_PORT`: WebUI port to access pgAdmin or phpMyAdmin (default: 8080).
* `PG_USERNAME`, `PG_PASSWORD`: Credentials to access pgAdmin for PostgreSQL.

</details>


### 3. Setup and Run

<details>
<summary><strong>Docker Compose Route</strong></summary>

Choose one supported database and optionally the corresponding manager.

## Supported Compose Profiles

| Database | Profile Name | Docker Hostname | WebUI Managers | Notes |
| ---------- | ------------ | --------------- | -------------- | ------------------------- |
| PostgreSQL | `postgresql` | `postgresql-db` | `pgadmin` | Recomended Setup |
| MySQL | `mysql` | `mysql-db` | `phpadmin` | - |
| MariaDB | `mariadb` | `mariadb-db` | `phpadmin` | - |
| SQLite | *(none)* | - | *(none)* | Use this for testing<br>or with low userbase |

---

## Running Examples

### - PostgreSQL + pgAdmin

```bash
docker compose --profile postgresql --profile pgadmin up
```

* Use `DB_TYPE=postgresql`
* Use `DB_PATH=postgresql-db`
* pgAdmin available at: [http://localhost:8080](http://localhost:8080)
* You can specify a different port by changing `DB_MANAGER_EXTERNAL_PORT`

---

### - MySQL + phpMyAdmin

```bash
docker compose --profile mysql --profile phpadmin up
```

* Use `DB_TYPE=mysql`
* Use `DB_PATH=mysql-db`
* phpMyAdmin available at: [http://localhost:8080](http://localhost:8080)
* You can specify a different port by changing `DB_MANAGER_EXTERNAL_PORT`

---

### - MariaDB + phpMyAdmin

```bash
docker compose --profile mariadb --profile phpadmin up
```

* Use `DB_TYPE=mariadb`
* Use `DB_PATH=mariadb-db`
* phpMyAdmin available at: [http://localhost:8080](http://localhost:8080)
* You can specify a different port by changing `DB_MANAGER_EXTERNAL_PORT`

---

### - SQLite (No Compose Profile)

SQLite works without any extra profile:

```bash
docker compose up
```

* Use `DB_TYPE=sqlite`
* Use `DB_PATH=data/db.sqlite`

---

### Stop Services

To shut everything down:

```bash
docker compose --profile "*" down
```

</details>

<details>
<summary><strong>Docker-less Route</strong></summary>

If you want to run the bot directly on your machine without Docker, follow these steps:

#### 1. Install system dependencies

Install the following packages:

* `libmagic1`
* `libmagic-dev`
* `ffmpeg`

For example, on Debian/Ubuntu:

```bash
sudo apt update
sudo apt install libmagic1 libmagic-dev ffmpeg
```
---
#### 2. Create venv inside repo folder
```bash
python3 -m venv .venv
```
---
#### 3. Activate venv
```bash
source .venv/bin/activate
```
---
#### 4. Install Python dependencies

```bash
pip install -r requirements.txt
```
---
#### 5. Run the bot

```bash
python -m txt2SpeechBot
```
91 changes: 91 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
services:
telegram-bot:
container_name: txt2SpeechBot
build: .
restart: unless-stopped
env_file:
- .env
volumes:
- ${HOST_PERSISTENT_PATH}/txt2SpeechBot/data:/usr/src/app/data

postgresql-db:
image: postgres:17
profiles: ["postgresql"]
container_name: txt2speech_postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME} -d ${DB_NAME}"]
interval: 5s
timeout: 2s
retries: 10
volumes:
- ${HOST_PERSISTENT_PATH}/txt2SpeechBot/data/postgresql:/var/lib/postgresql/data

pgadmin:
image: dpage/pgadmin4:latest
profiles: ["pgadmin"]
container_name: txt2speech_pgadmin
restart: unless-stopped
depends_on:
postgresql-db:
condition: service_healthy
environment:
PGADMIN_DEFAULT_EMAIL: ${PG_USERNAME}
PGADMIN_DEFAULT_PASSWORD: ${PG_PASSWORD}
ports:
- "${DB_MANAGER_EXTERNAL_PORT}:80"
volumes:
- ${HOST_PERSISTENT_PATH}/txt2SpeechBot/data/pgadmin:/var/lib/pgadmin

mysql-db:
image: mysql:9
container_name: txt2speech_mysql
profiles: ["mysql"]
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USERNAME}
MYSQL_PASSWORD: ${DB_PASSWORD}
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 5s
timeout: 2s
retries: 10
volumes:
- ${HOST_PERSISTENT_PATH}/txt2SpeechBot/data/mysql:/var/lib/mysql

mariadb-db:
image: mariadb:11
profiles: ["mariadb"]
container_name: txt2speech_mariadb
restart: unless-stopped
environment:
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MARIADB_DATABASE: ${DB_NAME}
MARIADB_USER: ${DB_USERNAME}
MARIADB_PASSWORD: ${DB_PASSWORD}
healthcheck:
# idk why this healthcheck doesn't work for mariadb
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 5s
timeout: 2s
retries: 10
volumes:
- ${HOST_PERSISTENT_PATH}/txt2SpeechBot/data/mariadb:/var/lib/mysql

phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
profiles: ["phpmyadmin"]
container_name: txt2speech_phpadmin
restart: unless-stopped
environment:
PMA_HOST: ${DB_PATH}
PMA_PORT: ${DB_PORT}
PMA_ARBITRARY: 1
ports:
- "${DB_MANAGER_EXTERNAL_PORT}:80"
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
requests
pyTelegramBotAPI
python-magic
pydub
mysql-connector-python
psycopg[binary,pool]
python-dotenv
audioop-lts; python_version>='3.13'
Loading