Skip to content

Commit 2bd51ca

Browse files
authored
Merge pull request #12 from dbccccccc/v2
v2
2 parents c142e25 + f2c9b16 commit 2bd51ca

22 files changed

+1048
-922
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HOST=localhost
2+
PORT=7000
3+
VERIFY_SSL=true
4+
MAX_QUEUE_SIZE=100
5+
RATE_LIMIT_REQUESTS=30
6+
RATE_LIMIT_WINDOW=60

.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ VERIFY_SSL=true
88
# Queue configuration
99
MAX_QUEUE_SIZE=100
1010
RATE_LIMIT_REQUESTS=30
11-
RATE_LIMIT_WINDOW=60
11+
RATE_LIMIT_WINDOW=60
12+
13+
# Flask configuration
14+
FLASK_ENV=production
15+
FLASK_APP=app.py

.github/workflows/docker-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
type=raw,value=latest,enable=${{ !github.event.release.prerelease }}
3737
labels: |
3838
org.opencontainers.image.source=${{ github.repositoryUrl }}
39+
org.opencontainers.image.description=TTS API server compatible with OpenAI's TTS API format
40+
org.opencontainers.image.licenses=MIT
3941
4042
- name: Build and push
4143
id: build-and-push

Dockerfile

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
# Use Python 3.13 slim image as base
22
FROM python:3.13-slim
33

4-
# Set working directory to root
5-
WORKDIR /
4+
# Install Redis
5+
RUN apt-get update && \
6+
apt-get install -y redis-server && \
7+
apt-get clean && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
# Set working directory
11+
WORKDIR /app
612

713
# Copy requirements first to leverage Docker cache
8-
COPY requirements.txt .
14+
COPY flask_app/requirements.txt .
915

1016
# Install dependencies
1117
RUN pip install --no-cache-dir -r requirements.txt
1218

13-
# Copy all application directories and files
14-
COPY main.py .
15-
COPY server/ server/
16-
COPY utils/ utils/
17-
COPY static/ static/
18-
COPY voices/ voices/
19+
# Copy Flask application
20+
COPY flask_app/ .
21+
22+
# Create directory for Redis data
23+
RUN mkdir -p /data/redis
1924

2025
# Set default environment variables
2126
ENV HOST=0.0.0.0 \
2227
PORT=7000 \
2328
VERIFY_SSL=true \
24-
MAX_QUEUE_SIZE=100
29+
MAX_QUEUE_SIZE=100 \
30+
FLASK_ENV=production \
31+
FLASK_APP=app.py \
32+
CELERY_BROKER_URL=redis://localhost:6379/0 \
33+
CELERY_RESULT_BACKEND=redis://localhost:6379/0
34+
35+
# Expose ports for Flask and Redis
36+
EXPOSE 7000 6379
2537

26-
# Expose port 7000
27-
EXPOSE 7000
38+
# Copy the startup script
39+
COPY docker-entrypoint.sh /usr/local/bin/
40+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
2841

29-
# Command to run the application
30-
CMD ["python", "main.py"]
42+
# Set the entrypoint
43+
ENTRYPOINT ["docker-entrypoint.sh"]

README.md

Lines changed: 81 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,102 +5,141 @@
55
[![GitHub Stars](https://img.shields.io/github/stars/dbccccccc/ttsfm?style=social)](https://github.com/dbccccccc/ttsfm)
66

77
> ⚠️ **Disclaimer**
8-
> This project is for learning and testing purposes only. For production environments, please use [OpenAI's official TTS service](https://platform.openai.com/docs/guides/audio).
8+
> This project is for learning & testing purposes only. For production use, please use the [official OpenAI TTS service](https://platform.openai.com/docs/guides/audio).
9+
10+
> ⚠️ **Development Notice**
11+
> The v2 branch is currently under active development and is not recommended for production use. Please use the latest stable release version instead.
912
1013
English | [中文](README_CN.md)
1114

12-
## 🌟 Project Introduction
15+
## 🌟 Project Overview
1316

14-
TTSFM is a reverse-engineered API server that is fully compatible with OpenAI's Text-to-Speech (TTS) interface.
17+
TTSFM is a API server that's fully compatible with OpenAI's Text-to-Speech (TTS) API format.
1518

16-
> 🎮 Try it now: [Official Demo Site](https://ttsapi.site/)
19+
> 🎮 Try it now: [Official Demo](https://ttsapi.site/)
1720
1821
## 🏗️ Project Structure
1922

2023
```text
2124
ttsfm/
22-
├── main.py # Application entry
23-
├── server/ # Core services
24-
│ ├── api.py # OpenAI-compatible API
25-
│ └── handlers.py # Request handlers
26-
├── utils/ # Utility modules
27-
│ └── config.py # Configuration management
28-
├── static/ # Frontend resources
29-
│ ├── index.html # English interface
30-
│ ├── index_zh.html # Chinese interface
31-
│ ├── script.js # Frontend JavaScript
32-
│ └── styles.css # Frontend styles
33-
├── pressure_test.py # Stress testing script
34-
├── Dockerfile # Docker configuration
25+
├── app.py # Main Flask application
26+
├── celery_worker.py # Celery configuration and tasks
3527
├── requirements.txt # Python dependencies
36-
└── .env.example # Environment variables template
28+
├── static/ # Frontend resources
29+
│ ├── index.html # English interface
30+
│ ├── index_zh.html # Chinese interface
31+
│ ├── script.js # Frontend JavaScript
32+
│ └── styles.css # Frontend styles
33+
├── voices/ # Voice samples
34+
├── Dockerfile # Docker configuration
35+
├── docker-entrypoint.sh # Docker startup script
36+
├── .env.example # Environment variables template
37+
├── .env # Environment variables
38+
├── .gitignore # Git ignore rules
39+
├── LICENSE # MIT License
40+
├── README.md # English documentation
41+
├── README_CN.md # Chinese documentation
42+
├── test_api.py # API test suite
43+
├── test_queue.py # Queue test suite
44+
└── .github/ # GitHub workflows
3745
```
3846

3947
## 🚀 Quick Start
4048

4149
### System Requirements
42-
- Python ≥ 3.8
43-
- Or Docker environment
50+
- Docker and Docker Compose
51+
- or Python ≥ 3.8 with Redis
4452

4553
### 🐳 Docker Run (Recommended)
4654

4755
Basic usage:
4856
```bash
49-
docker run -p 7000:7000 dbcccc/ttsfm:latest
57+
docker run -p 7000:7000 -p 6379:6379 dbcccc/ttsfm:latest
5058
```
5159

52-
Custom configuration using environment variables:
60+
Custom configuration with environment variables:
5361
```bash
5462
docker run -d \
5563
-p 7000:7000 \
64+
-p 6379:6379 \
5665
-e HOST=0.0.0.0 \
5766
-e PORT=7000 \
5867
-e VERIFY_SSL=true \
5968
-e MAX_QUEUE_SIZE=100 \
6069
-e RATE_LIMIT_REQUESTS=30 \
6170
-e RATE_LIMIT_WINDOW=60 \
71+
-e CELERY_BROKER_URL=redis://localhost:6379/0 \
72+
-e CELERY_RESULT_BACKEND=redis://localhost:6379/0 \
6273
dbcccc/ttsfm:latest
6374
```
6475

6576
Available environment variables:
6677
- `HOST`: Server host (default: 0.0.0.0)
6778
- `PORT`: Server port (default: 7000)
68-
- `VERIFY_SSL`: Whether to verify SSL certificates (default: true)
69-
- `MAX_QUEUE_SIZE`: Maximum number of tasks in queue (default: 100)
70-
- `RATE_LIMIT_REQUESTS`: Maximum number of requests per time window (default: 30)
71-
- `RATE_LIMIT_WINDOW`: Time window in seconds for rate limiting (default: 60)
72-
73-
> 💡 **Tip**
74-
> MacOS users experiencing port conflicts can use alternative ports:
75-
> `docker run -p 5051:7000 dbcccc/ttsfm:latest`
79+
- `VERIFY_SSL`: Verify SSL certificates (default: true)
80+
- `MAX_QUEUE_SIZE`: Maximum queue size (default: 100)
81+
- `RATE_LIMIT_REQUESTS`: Maximum requests per time window (default: 30)
82+
- `RATE_LIMIT_WINDOW`: Rate limit time window in seconds (default: 60)
83+
- `CELERY_BROKER_URL`: Redis broker URL (default: redis://localhost:6379/0)
84+
- `CELERY_RESULT_BACKEND`: Redis result backend URL (default: redis://localhost:6379/0)
7685

7786
### 📦 Manual Installation
7887

79-
1. Download the latest release package from [GitHub Releases](https://github.com/dbccccccc/ttsfm/releases)
80-
2. Extract and enter the directory:
88+
1. Clone the repository:
8189
```bash
82-
tar -zxvf ttsfm-vX.X.X.tar.gz
83-
cd ttsfm-vX.X.X
90+
git clone https://github.com/dbccccccc/ttsfm.git
91+
cd ttsfm
8492
```
85-
3. Install dependencies and launch:
93+
94+
2. Install dependencies and start:
8695
```bash
96+
cd flask_app
8797
pip install -r requirements.txt
88-
cp .env.example .env # Edit config as needed
89-
python main.py
98+
99+
# Start Redis server
100+
redis-server
101+
102+
# In a new terminal, start Celery worker
103+
celery -A celery_worker.celery worker --pool=solo -l info
104+
105+
# In another terminal, start Flask application
106+
python app.py
90107
```
91108

92109
## 📚 Usage Guide
93110

94111
### Web Interface
95-
Access `http://localhost:7000` to experience the interactive demo
112+
Visit `http://localhost:7000` for the interactive demo
96113

97114
### API Endpoints
98115
| Endpoint | Method | Description |
99-
|------|------|-------------|
100-
| `/v1/audio/speech` | POST | Text-to-Speech |
116+
|----------|--------|-------------|
117+
| `/v1/audio/speech` | POST | Text to Speech |
101118
| `/api/queue-size` | GET | Query task queue |
119+
| `/api/voice-sample/<voice>` | GET | Get voice sample |
120+
| `/api/version` | GET | Get API version |
102121

103-
> 🔍 Complete API documentation is available via the web interface after local deployment
122+
> 🔍 Complete API documentation is available in the web interface after local deployment
123+
124+
## 🔧 Architecture
125+
126+
The application uses a distributed task queue architecture:
127+
128+
1. **Flask Application**: Handles HTTP requests and serves the web interface
129+
2. **Celery**: Manages asynchronous task processing
130+
3. **Redis**: Acts as message broker and result backend
131+
4. **Task Queue**: Processes TTS requests asynchronously
132+
133+
```mermaid
134+
graph TD
135+
A[Client] -->|HTTP Request| B[Flask App]
136+
B -->|Task| C[Celery]
137+
C -->|Queue| D[Redis]
138+
D -->|Process| E[Celery Worker]
139+
E -->|Result| D
140+
D -->|Response| B
141+
B -->|HTTP Response| A
142+
```
104143

105144
## 🤝 Contributing
106145

@@ -114,4 +153,4 @@ We welcome all forms of contributions! You can participate by:
114153

115154
## 📈 Project Activity
116155

117-
[![Star History Chart](https://api.star-history.com/svg?repos=dbccccccc/ttsfm&type=Date)](https://star-history.com/#dbccccccc/ttsfm&Date)
156+
[![Star History Chart](https://api.star-history.com/svg?repos=dbccccccc/ttsfm&type=Date)](https://star-history.com/#dbccccccc/ttsfm&Date)

0 commit comments

Comments
 (0)