mirror of
https://github.com/FunAudioLLM/CosyVoice.git
synced 2026-02-04 17:39:25 +08:00
add fastapi usage
This commit is contained in:
@@ -66,7 +66,7 @@ if __name__ == "__main__":
|
||||
default='希望你以后能够做的比我还好呦。')
|
||||
parser.add_argument('--prompt_wav',
|
||||
type=str,
|
||||
default='../../zero_shot_prompt.wav')
|
||||
default='../../../zero_shot_prompt.wav')
|
||||
parser.add_argument('--instruct_text',
|
||||
type=str,
|
||||
default='Theo \'Crimson\', is a fiery, passionate rebel leader. Fights with fervor for justice, but struggles with impulsiveness.')
|
||||
@@ -1,9 +1,9 @@
|
||||
# Set inference model
|
||||
# export MODEL_DIR=pretrained_models/CosyVoice-300M-Instruct
|
||||
# For development
|
||||
# fastapi dev --port 6006 fastapi_server.py
|
||||
# fastapi dev --port 6006 fastapi_server.py
|
||||
# For production deployment
|
||||
# fastapi run --port 6006 fastapi_server.py
|
||||
# fastapi run --port 6006 fastapi_server.py
|
||||
|
||||
import os
|
||||
import sys
|
||||
@@ -12,8 +12,8 @@ from fastapi import FastAPI, Response, File, UploadFile, Form
|
||||
from fastapi.responses import HTMLResponse
|
||||
from contextlib import asynccontextmanager
|
||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.append('{}/../..'.format(ROOT_DIR))
|
||||
sys.path.append('{}/../../third_party/Matcha-TTS'.format(ROOT_DIR))
|
||||
sys.path.append('{}/../../..'.format(ROOT_DIR))
|
||||
sys.path.append('{}/../../../third_party/Matcha-TTS'.format(ROOT_DIR))
|
||||
from cosyvoice.cli.cosyvoice import CosyVoice
|
||||
from cosyvoice.utils.file_utils import load_wav
|
||||
import numpy as np
|
||||
@@ -30,7 +30,7 @@ async def lifespan(app: FastAPI):
|
||||
model_dir = os.getenv("MODEL_DIR", "pretrained_models/CosyVoice-300M-SFT")
|
||||
if model_dir:
|
||||
logging.info("MODEL_DIR is {}", model_dir)
|
||||
app.cosyvoice = CosyVoice('../../'+model_dir)
|
||||
app.cosyvoice = CosyVoice(model_dir)
|
||||
# sft usage
|
||||
logging.info("Avaliable speakers {}", app.cosyvoice.list_avaliable_spks())
|
||||
else:
|
||||
Reference in New Issue
Block a user