Add local MeloTTS support
This commit is contained in:
18
docker/melotts/Dockerfile
Normal file
18
docker/melotts/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
FROM python:3.9-slim
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
WORKDIR /opt/realtime-voice-bot
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
git \
|
||||
libsndfile1 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN pip install --no-cache-dir git+https://github.com/myshell-ai/MeloTTS.git@v0.1.2
|
||||
RUN python -m unidic download
|
||||
|
||||
COPY melo_tts_cli.py /opt/realtime-voice-bot/melo_tts_cli.py
|
||||
|
||||
ENTRYPOINT ["python", "/opt/realtime-voice-bot/melo_tts_cli.py"]
|
||||
36
docker/melotts/melo_tts_cli.py
Normal file
36
docker/melotts/melo_tts_cli.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
from melo.api import TTS
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--text", required=True)
|
||||
parser.add_argument("--output", required=True)
|
||||
parser.add_argument("--language", default="KR")
|
||||
parser.add_argument("--speaker", default="KR")
|
||||
parser.add_argument("--speed", type=float, default=1.0)
|
||||
parser.add_argument("--device", default="cpu")
|
||||
args = parser.parse_args()
|
||||
|
||||
output_path = Path(args.output)
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
model = TTS(language=args.language, device=args.device)
|
||||
speaker_ids = model.hps.data.spk2id
|
||||
|
||||
if args.speaker not in speaker_ids:
|
||||
supported = ", ".join(sorted(speaker_ids.keys()))
|
||||
raise SystemExit(f"지원하지 않는 speaker 입니다: {args.speaker}. 사용 가능: {supported}")
|
||||
|
||||
model.tts_to_file(
|
||||
args.text,
|
||||
speaker_ids[args.speaker],
|
||||
str(output_path),
|
||||
speed=args.speed,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user