Skip to content

Commit

Permalink
Merge pull request #940 from c4fun/fastapi-cosyvoice2
Browse files Browse the repository at this point in the history
Add a inference_instruct2 route to support and defaultly supports cosyvoice2 in fastapi server
  • Loading branch information
aluminumbox authored Feb 7, 2025
2 parents da3f129 + ba6d8c0 commit 95e99e0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion runtime/python/fastapi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ async def inference_instruct(tts_text: str = Form(), spk_id: str = Form(), instr
model_output = cosyvoice.inference_instruct(tts_text, spk_id, instruct_text)
return StreamingResponse(generate_data(model_output))

@app.get("/inference_instruct2")
@app.post("/inference_instruct2")
async def inference_instruct2(tts_text: str = Form(), instruct_text: str = Form(), prompt_wav: UploadFile = File()):
prompt_speech_16k = load_wav(prompt_wav.file, 16000)
model_output = cosyvoice.inference_instruct2(tts_text, instruct_text, prompt_speech_16k)
return StreamingResponse(generate_data(model_output))



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

0 comments on commit 95e99e0

Please sign in to comment.