feat: update Dockerfile and README for TTS service setup and usage instructions
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -25,3 +25,4 @@ go.work.sum
|
|||||||
# env file
|
# env file
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
|||||||
23
Dockerfile
23
Dockerfile
@@ -1,7 +1,7 @@
|
|||||||
# 使用官方 Golang 镜像作为构建环境
|
# 使用官方 Golang 镜像作为构建环境
|
||||||
FROM golang:1.22-alpine as builder
|
FROM golang:1.22-alpine AS builder
|
||||||
ENV CGO_ENABLED 0
|
ENV CGO_ENABLED=0
|
||||||
ENV GOPROXY https://goproxy.cn,direct
|
ENV GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
# 设置工作目录
|
# 设置工作目录
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -16,17 +16,24 @@ RUN go mod download
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# 构建 Go 应用程序
|
# 构建 Go 应用程序
|
||||||
RUN go build -o main . && ls
|
RUN go build -o main ./cmd/api/main.go
|
||||||
|
|
||||||
|
|
||||||
# 使用 scratch 作为基础镜像
|
# 使用 alpine 作为基础镜像
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
|
# 安装 ffmpeg 和 CA 证书
|
||||||
|
RUN apk update --no-cache && \
|
||||||
|
apk add --no-cache ca-certificates ffmpeg tzdata && \
|
||||||
|
rm -rf /var/cache/apk/*
|
||||||
|
|
||||||
# 从 builder 阶段复制可执行文件到当前阶段
|
# 从 builder 阶段复制可执行文件到当前阶段
|
||||||
COPY --from=builder /app/main .
|
COPY --from=builder /app/main .
|
||||||
COPY --from=builder /app/templates ./templates
|
COPY --from=builder /app/web ./web
|
||||||
RUN apk update --no-cache && apk add --no-cache ca-certificates
|
COPY --from=builder /app/configs ./configs
|
||||||
ENV TZ Asia/Shanghai
|
|
||||||
|
# 设置时区
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
# 暴露端口
|
# 暴露端口
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|||||||
94
README.md
94
README.md
@@ -1,9 +1,97 @@
|
|||||||
# docker 部署
|
# TTS 服务
|
||||||
|
|
||||||
|
一个简单易用的文本转语音 (TTS) 服务,基于 Microsoft Azure 语音服务,提供高质量的语音合成能力。
|
||||||
|
|
||||||
|
## 功能特点
|
||||||
|
|
||||||
|
- 支持多种语言和声音
|
||||||
|
- 可调节语速和语调
|
||||||
|
- 支持多种输出音频格式
|
||||||
|
- 兼容 OpenAI TTS API
|
||||||
|
- 支持长文本自动分割与合并
|
||||||
|
- 提供 Web UI 和 RESTful API
|
||||||
|
|
||||||
|
## 快速开始
|
||||||
|
|
||||||
|
### Docker 部署
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker run -d -p 8080:8080 --name=tts zuoban/zb-tts
|
docker run -d -p 8080:8080 --name=tts zuoban/zb-tts
|
||||||
```
|
```
|
||||||
|
|
||||||
|
部署完成后,访问 `http://localhost:8080` 使用 Web 界面,或通过 `http://localhost:8080/api-doc` 查看 API 文档。
|
||||||
|
|
||||||
# cloudflare worker 部署
|
### Cloudflare Worker 部署
|
||||||
[worker.js](https://raw.githubusercontent.com/zuoban/tts/main/templates/worker.js)
|
|
||||||
|
1. 创建一个新的 Cloudflare Worker
|
||||||
|
2. 复制以下脚本内容到 Worker
|
||||||
|
[worker.js](https://raw.githubusercontent.com/zuoban/tts/main/web/templates/worker.js)
|
||||||
|
|
||||||
|
## API 使用示例
|
||||||
|
|
||||||
|
### 基础 API
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# 基础文本转语音
|
||||||
|
curl "http://localhost:8080/tts?t=你好,世界&v=zh-CN-XiaoxiaoNeural"
|
||||||
|
|
||||||
|
# 调整语速和语调
|
||||||
|
curl "http://localhost:8080/tts?t=你好,世界&v=zh-CN-XiaoxiaoNeural&r=20&p=10"
|
||||||
|
|
||||||
|
# 使用情感风格
|
||||||
|
curl "http://localhost:8080/tts?t=今天天气真好&v=zh-CN-XiaoxiaoNeural&s=cheerful"
|
||||||
|
```
|
||||||
|
|
||||||
|
### OpenAI 兼容 API
|
||||||
|
|
||||||
|
```shell
|
||||||
|
curl -X POST "http://localhost:8080/v1/audio/speech" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"model": "tts-1",
|
||||||
|
"input": "你好,世界!",
|
||||||
|
"voice": "zh-CN-XiaoxiaoNeural"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
## 配置选项
|
||||||
|
|
||||||
|
您可以通过环境变量或配置文件自定义 TTS 服务:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# 使用自定义端口
|
||||||
|
docker run -d -p 9000:9000 -e PORT=9000 --name=tts zuoban/zb-tts
|
||||||
|
|
||||||
|
# 使用配置文件
|
||||||
|
docker run -d -p 8080:8080 -v /path/to/config.yaml:/app/config.yaml --name=tts zuoban/zb-tts
|
||||||
|
```
|
||||||
|
|
||||||
|
## 本地构建与运行
|
||||||
|
|
||||||
|
要从源码构建和运行:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# 克隆仓库
|
||||||
|
git clone https://github.com/zuoban/tts.git
|
||||||
|
cd tts
|
||||||
|
|
||||||
|
# 构建
|
||||||
|
go build -o tts ./cmd/api
|
||||||
|
|
||||||
|
# 运行
|
||||||
|
./tts
|
||||||
|
```
|
||||||
|
|
||||||
|
## 支持的音频格式
|
||||||
|
|
||||||
|
- MP3: `audio-24khz-48kbitrate-mono-mp3`(默认)
|
||||||
|
- MP3: `audio-24khz-96kbitrate-mono-mp3`
|
||||||
|
- MP3: `audio-24khz-160kbitrate-mono-mp3`
|
||||||
|
- WAV: `riff-24khz-16bit-mono-pcm`
|
||||||
|
- OGG: `ogg-24khz-16bit-mono-opus`
|
||||||
|
|
||||||
|
更多格式请参考 API 文档。
|
||||||
|
|
||||||
|
## 许可证
|
||||||
|
|
||||||
|
MIT
|
||||||
@@ -66,8 +66,6 @@ func (a *App) Start() error {
|
|||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
return err
|
return err
|
||||||
case <-quit:
|
case <-quit:
|
||||||
log.Println("接收到退出信号,正在优雅关闭...")
|
|
||||||
|
|
||||||
// 创建一个超时上下文用于优雅关闭
|
// 创建一个超时上下文用于优雅关闭
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
Reference in New Issue
Block a user