Spaces:
Runtime error
Runtime error
dockerfile
Browse files- Dockerfile +20 -0
- docker-compose.yml +11 -0
- main.py +32 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.8
|
2 |
+
|
3 |
+
RUN apt-get update -y
|
4 |
+
RUN apt-get install ffmpeg -y
|
5 |
+
RUN apt-get install vim -y
|
6 |
+
RUN apt-get update -y
|
7 |
+
RUN apt-get install fonts-noto-cjk fonts-noto-color-emoji
|
8 |
+
|
9 |
+
RUN pip install --upgrade pip
|
10 |
+
|
11 |
+
WORKDIR /app
|
12 |
+
|
13 |
+
ADD ./requirements.txt /app/requirements.txt
|
14 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
15 |
+
|
16 |
+
ADD ./ /app/
|
17 |
+
|
18 |
+
RUN mkdir -p /usr/local/var/log
|
19 |
+
|
20 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
docker-compose.yml
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: "3"
|
2 |
+
services:
|
3 |
+
tts_sambert_hifigan:
|
4 |
+
build: .
|
5 |
+
command: python -m uvicorn main:app --host 0.0.0.0 --port 8001 --reload
|
6 |
+
restart: always
|
7 |
+
volumes:
|
8 |
+
- .:/app
|
9 |
+
- /etc/localtime:/etc/localtime # 同步时间
|
10 |
+
ports:
|
11 |
+
- "8001:8001"
|
main.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
from typing import Union
|
4 |
+
|
5 |
+
from fastapi import FastAPI
|
6 |
+
from fastapi.responses import FileResponse
|
7 |
+
from modelscope.outputs import OutputKeys
|
8 |
+
from modelscope.pipelines import pipeline
|
9 |
+
from modelscope.utils.constant import Tasks
|
10 |
+
from datetime import datetime
|
11 |
+
|
12 |
+
model_id = "damo/speech_sambert-hifigan_tts_zhitian_emo_zh-cn_16k"
|
13 |
+
sambert_hifigan_tts = pipeline(task=Tasks.text_to_speech, model=model_id)
|
14 |
+
|
15 |
+
app = FastAPI()
|
16 |
+
|
17 |
+
|
18 |
+
def generate_audio(text: str):
|
19 |
+
output = sambert_hifigan_tts(input=text)
|
20 |
+
wav = output[OutputKeys.OUTPUT_WAV]
|
21 |
+
timestamp = datetime.now().strftime("%Y%m%d%H%M%S") # Generate timestamp
|
22 |
+
filename = f"media/audio/{timestamp}.wav" # Use timestamp as filename
|
23 |
+
os.makedirs(os.path.dirname(filename), exist_ok=True) # Create directories if they don't exist
|
24 |
+
with open(filename, "wb") as f:
|
25 |
+
f.write(wav)
|
26 |
+
return filename
|
27 |
+
|
28 |
+
|
29 |
+
@app.get("/tts", responses={200: {"content": {"audio/wav": {}}}})
|
30 |
+
def get_tts(text: Union[str, None] = None):
|
31 |
+
filename = generate_audio(text)
|
32 |
+
return FileResponse(filename, filename=f"{os.path.basename(filename)}")
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
|
2 |
+
modelscope[audio]
|
3 |
+
fastapi
|
4 |
+
uvicorn[standard]
|