add inference api
This commit is contained in:
1673
poetry.lock
generated
1673
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,9 @@ description = ""
|
|||||||
authors = ["Ftps <ftpsflandre@gmail.com>"]
|
authors = ["Ftps <ftpsflandre@gmail.com>"]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
|
[tool.poetry.urls]
|
||||||
|
github = "https://github.com/RVC-Project/Retrieval-based-Voice-Conversion"
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "3.11.2"
|
python = "3.11.2"
|
||||||
torch = "^2.1.0"
|
torch = "^2.1.0"
|
||||||
@@ -20,9 +23,19 @@ python-dotenv = "^1.0.0"
|
|||||||
pydub = "^0.25.1"
|
pydub = "^0.25.1"
|
||||||
click = "^8.1.7"
|
click = "^8.1.7"
|
||||||
tensorboardx = "^2.6.2.2"
|
tensorboardx = "^2.6.2.2"
|
||||||
|
poethepoet = "^0.24.4"
|
||||||
|
uvicorn = {version = "^0.26.0", optional=true}
|
||||||
|
fastapi = "^0.109.0"
|
||||||
|
python-multipart = {version = "^0.0.6", optional=true}
|
||||||
|
|
||||||
|
[tool.poetry.extras]
|
||||||
|
api = ["uvicorn", "fastapi"]
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
rvc = "rvc.cli.cli:main"
|
rvc = "rvc.utils.cli.cli:main"
|
||||||
|
|
||||||
|
[tool.poe.tasks]
|
||||||
|
rvc-api = "uvicorn rvc.utils.api.api:app --reload"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
|
|||||||
11
rvc/utils/api/api.py
Normal file
11
rvc/utils/api/api.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from dotenv import load_dotenv
|
||||||
|
from fastapi import FastAPI
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
from rvc.utils.api.endpoints import inference
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
app.include_router(inference.router)
|
||||||
50
rvc/utils/api/endpoints/inference.py
Normal file
50
rvc/utils/api/endpoints/inference.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
from io import BytesIO
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from fastapi import APIRouter, UploadFile, Response, responses
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from scipy.io import wavfile
|
||||||
|
|
||||||
|
from rvc.modules.vc.modules import VC
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/inference")
|
||||||
|
def inference(
|
||||||
|
modelpath: str | UploadFile,
|
||||||
|
input: Path | UploadFile,
|
||||||
|
sid: int = 0,
|
||||||
|
f0_up_key: int = 0,
|
||||||
|
f0_method: str = "rmvpe",
|
||||||
|
f0_file: Path | None = None,
|
||||||
|
index_file: Path | None = None,
|
||||||
|
index_rate: float = 0.75,
|
||||||
|
filter_radius: int = 3,
|
||||||
|
resample_sr: int = 0,
|
||||||
|
rms_mix_rate: float = 0.25,
|
||||||
|
protect: float = 0.33,
|
||||||
|
):
|
||||||
|
print(protect)
|
||||||
|
vc = VC()
|
||||||
|
vc.get_vc(modelpath)
|
||||||
|
tgt_sr, audio_opt, times, _ = vc.vc_single(
|
||||||
|
sid,
|
||||||
|
input,
|
||||||
|
f0_up_key,
|
||||||
|
f0_method,
|
||||||
|
f0_file,
|
||||||
|
index_file,
|
||||||
|
index_rate,
|
||||||
|
filter_radius,
|
||||||
|
resample_sr,
|
||||||
|
rms_mix_rate,
|
||||||
|
protect,
|
||||||
|
)
|
||||||
|
wavfile.write(wv := BytesIO(), tgt_sr, audio_opt)
|
||||||
|
print(times)
|
||||||
|
return responses.StreamingResponse(
|
||||||
|
wv,
|
||||||
|
media_type="audio/wav",
|
||||||
|
headers={"Content-Disposition": "attachment; filename=inference.wav"},
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user