lijiacai commited on
Commit
69e5ee8
·
1 Parent(s): cfe558f
Files changed (2) hide show
  1. download.py +2 -1
  2. main.py +8 -3
download.py CHANGED
@@ -51,4 +51,5 @@ def download_nltk_data():
51
 
52
 
53
  if __name__ == '__main__':
54
- download()
 
 
51
 
52
 
53
  if __name__ == '__main__':
54
+ download()
55
+ download_nltk_data()
main.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, Body, File, Form, UploadFile
2
  from fastapi.responses import FileResponse
3
  from fastapi.staticfiles import StaticFiles
4
  from model import clone_voice
@@ -29,7 +29,6 @@ async def tts(
29
  voice: DefaultVoice = Form(None),
30
  text: str = Form(..., description="转换文本")
31
  ):
32
-
33
  if custom_voice_file is not None:
34
  os.makedirs("static/tmp", exist_ok=True)
35
  content = await file.read()
@@ -39,7 +38,13 @@ async def tts(
39
  voice = filename
40
  wav_path = clone_voice(
41
  user_voice=voice, user_text=text, user_lang=language)
42
- return FileResponse(wav_path)
 
 
 
 
 
 
43
 
44
 
45
  if __name__ == '__main__':
 
1
+ from fastapi import FastAPI, Body, File, Form, UploadFile, Response
2
  from fastapi.responses import FileResponse
3
  from fastapi.staticfiles import StaticFiles
4
  from model import clone_voice
 
29
  voice: DefaultVoice = Form(None),
30
  text: str = Form(..., description="转换文本")
31
  ):
 
32
  if custom_voice_file is not None:
33
  os.makedirs("static/tmp", exist_ok=True)
34
  content = await file.read()
 
38
  voice = filename
39
  wav_path = clone_voice(
40
  user_voice=voice, user_text=text, user_lang=language)
41
+ headers = {
42
+ "Content-Disposition": "attachment; filename=result.wav",
43
+ "Content-Type": "audio/wav",
44
+ }
45
+ with open(wav_path, "rb") as audio_file:
46
+ audio_content = audio_file.read()
47
+ return Response(audio_content, headers=headers)
48
 
49
 
50
  if __name__ == '__main__':