forked from yihong0618/ChatTTS
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Build Docker chattts image | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.CR_PAT }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: ghcr.io/${{ github.repository_owner }}/chattts:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.8-slim | ||
|
||
RUN apt-get update && apt-get install -y gcc libgomp1 && apt-get clean | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt . | ||
|
||
RUN pip3 install --no-cache-dir -r requirements.txt | ||
|
||
COPY . . | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3.8' | ||
|
||
services: | ||
chattts: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "8000:8000" | ||
environment: | ||
- ENV=production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
import wave | ||
import numpy as np | ||
from fastapi import FastAPI, HTTPException, Depends | ||
import pydantic | ||
import ChatTTS | ||
|
||
app = FastAPI() | ||
|
||
|
||
class TTSInput(pydantic.BaseModel): | ||
text: str | ||
output_path: str | ||
seed: int = 42 | ||
|
||
|
||
def get_chat_model() -> ChatTTS.Chat: | ||
chat = ChatTTS.Chat() | ||
chat.load_models() | ||
return chat | ||
|
||
|
||
@app.post("/tts") | ||
def tts(input: TTSInput, chat: ChatTTS.Chat = Depends(get_chat_model)): | ||
try: | ||
texts = [input.text] | ||
r = chat.sample_random_speaker(seed=input.seed) | ||
|
||
params_infer_code = { | ||
'spk_emb': r, # add sampled speaker | ||
'temperature': .3, # using customtemperature | ||
'top_P': 0.7, # top P decode | ||
'top_K': 20, # top K decode | ||
} | ||
|
||
params_refine_text = { | ||
'prompt': '[oral_2][laugh_0][break_6]' | ||
} | ||
|
||
wavs = chat.infer(texts, | ||
params_infer_code=params_infer_code, | ||
params_refine_text=params_refine_text, use_decoder=True) | ||
|
||
audio_data = np.array(wavs[0], dtype=np.float32) | ||
sample_rate = 24000 | ||
audio_data = (audio_data * 32767).astype(np.int16) | ||
|
||
with wave.open(input.output_path, "w") as wf: | ||
wf.setnchannels(1) | ||
wf.setsampwidth(2) | ||
wf.setframerate(sample_rate) | ||
wf.writeframes(audio_data.tobytes()) | ||
return {"output_path": input.output_path} | ||
|
||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ einops | |
vector_quantize_pytorch | ||
transformers~=4.41.1 | ||
vocos | ||
fastapi | ||
uvicorn | ||
starlette | ||
pydantic |