zhendery commited on
Commit
81ecfab
·
1 Parent(s): c786b94

添加调试信息

Browse files
Files changed (2) hide show
  1. api.py +6 -2
  2. utils.py +5 -0
api.py CHANGED
@@ -7,8 +7,11 @@ from pydantic import BaseModel
7
  import os
8
  import requests
9
  import zipfile
 
10
 
 
11
  model = VoxCPM.from_pretrained("openbmb/VoxCPM-0.5B")
 
12
 
13
  security = HTTPBearer()
14
  app = FastAPI()
@@ -34,7 +37,7 @@ def generate_tts(request: GenerateRequest, token: str = Depends(verify_token)):
34
  text = (request.text or "").strip()
35
  if len(text) == 0:
36
  raise ValueError("Please input text to synthesize.")
37
- print(f"Generating audio for text: '{text[:60]}...'")
38
 
39
  with open(f"/workspace/voices/{request.voice}.pmt", 'r', encoding='utf-8') as f:
40
  wav = model.generate(
@@ -48,6 +51,7 @@ def generate_tts(request: GenerateRequest, token: str = Depends(verify_token)):
48
  )
49
 
50
  sf.write("output.wav", wav, 16000)
 
51
  return Response(content=open("output.wav", 'rb').read(), media_type="audio/wav")
52
 
53
 
@@ -80,7 +84,7 @@ def download_voices():
80
  os.remove(zip_path)
81
 
82
  except Exception as e:
83
- print(f"Failed to download and extract voices: {e}")
84
  raise HTTPException(status_code=500, detail="Failed to download voice files")
85
 
86
  @app.post("/upload_voice")
 
7
  import os
8
  import requests
9
  import zipfile
10
+ from utils import *
11
 
12
+ print_with_time("Loading VoxCPM model...")
13
  model = VoxCPM.from_pretrained("openbmb/VoxCPM-0.5B")
14
+ print_with_time("VoxCPM model loaded.")
15
 
16
  security = HTTPBearer()
17
  app = FastAPI()
 
37
  text = (request.text or "").strip()
38
  if len(text) == 0:
39
  raise ValueError("Please input text to synthesize.")
40
+ print_with_time(f"Generating audio for text: '{text[:60]}...'")
41
 
42
  with open(f"/workspace/voices/{request.voice}.pmt", 'r', encoding='utf-8') as f:
43
  wav = model.generate(
 
51
  )
52
 
53
  sf.write("output.wav", wav, 16000)
54
+ print_with_time(f"Audio generated, saving to output.wav")
55
  return Response(content=open("output.wav", 'rb').read(), media_type="audio/wav")
56
 
57
 
 
84
  os.remove(zip_path)
85
 
86
  except Exception as e:
87
+ print_with_time(f"Failed to download and extract voices: {e}")
88
  raise HTTPException(status_code=500, detail="Failed to download voice files")
89
 
90
  @app.post("/upload_voice")
utils.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import datetime
2
+
3
+ def print_with_time(*args):
4
+ timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
5
+ print(f"{timestamp}: ", *args)