Skip to content

Commit 95e99e0

Browse files
authored
Merge pull request #940 from c4fun/fastapi-cosyvoice2
Add a inference_instruct2 route to support and defaultly supports cosyvoice2 in fastapi server
2 parents da3f129 + ba6d8c0 commit 95e99e0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

runtime/python/fastapi/server.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ async def inference_instruct(tts_text: str = Form(), spk_id: str = Form(), instr
7272
model_output = cosyvoice.inference_instruct(tts_text, spk_id, instruct_text)
7373
return StreamingResponse(generate_data(model_output))
7474

75+
@app.get("/inference_instruct2")
76+
@app.post("/inference_instruct2")
77+
async def inference_instruct2(tts_text: str = Form(), instruct_text: str = Form(), prompt_wav: UploadFile = File()):
78+
prompt_speech_16k = load_wav(prompt_wav.file, 16000)
79+
model_output = cosyvoice.inference_instruct2(tts_text, instruct_text, prompt_speech_16k)
80+
return StreamingResponse(generate_data(model_output))
81+
82+
7583

7684
if __name__ == '__main__':
7785
parser = argparse.ArgumentParser()
@@ -90,4 +98,4 @@ async def inference_instruct(tts_text: str = Form(), spk_id: str = Form(), instr
9098
cosyvoice = CosyVoice2(args.model_dir)
9199
except Exception:
92100
raise TypeError('no valid model_type!')
93-
uvicorn.run(app, host="0.0.0.0", port=args.port)
101+
uvicorn.run(app, host="0.0.0.0", port=args.port)

0 commit comments

Comments
 (0)