添加实体抽取接口
parent
385c41486f
commit
bfcdae9699
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="virtual_patient_qa" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="interrorobot" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
@ -1,3 +1,44 @@
|
|||||||
|
from fastapi import FastAPI, HTTPException
|
||||||
|
from pydantic import BaseModel
|
||||||
from paddlespeech.cli.tts.infer import TTSExecutor
|
from paddlespeech.cli.tts.infer import TTSExecutor
|
||||||
tts = TTSExecutor()
|
|
||||||
tts(text="今天天气十分不错。", output="output.wav")
|
app = FastAPI()
|
||||||
|
tts_executor = TTSExecutor()
|
||||||
|
|
||||||
|
|
||||||
|
class TextRequest(BaseModel):
|
||||||
|
text: str
|
||||||
|
|
||||||
|
|
||||||
|
def warm_up_tts():
|
||||||
|
default_text = "初始化文本" # 你可以使用任何你喜欢的文本
|
||||||
|
output_file = "warm_up_output.wav" # 暖身合成结果的输出文件名
|
||||||
|
|
||||||
|
# 调用合成功能
|
||||||
|
try:
|
||||||
|
tts_executor(text=default_text, output=output_file)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error during warm-up: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
# 在应用启动时进行暖身合成
|
||||||
|
warm_up_tts()
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/synthesize/")
|
||||||
|
async def synthesize_text(text_request: TextRequest):
|
||||||
|
text = text_request.text
|
||||||
|
output_file = "output.wav" # You can customize the output file name if needed
|
||||||
|
|
||||||
|
try:
|
||||||
|
tts_executor(text=text, output=output_file)
|
||||||
|
return {"message": "语音合成成功", "output_file": output_file}
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import uvicorn
|
||||||
|
|
||||||
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||||
|
Loading…
Reference in New Issue