ChuxiJ commited on
Commit
e3a1c8f
·
2 Parent(s): 1241c8025f8a0c

Merge branch 'main' of https://github.com/ace-step/ACE-Step-1.5 into main

Browse files
Files changed (1) hide show
  1. acestep/api_server.py +31 -3
acestep/api_server.py CHANGED
@@ -280,6 +280,15 @@ def create_app() -> FastAPI:
280
  INITIAL_AVG_JOB_SECONDS = float(os.getenv("ACESTEP_AVG_JOB_SECONDS", "5.0"))
281
  AVG_WINDOW = int(os.getenv("ACESTEP_AVG_WINDOW", "50"))
282
 
 
 
 
 
 
 
 
 
 
283
  @asynccontextmanager
284
  async def lifespan(app: FastAPI):
285
  # Clear proxy env that may affect downstream libs
@@ -736,9 +745,9 @@ def create_app() -> FastAPI:
736
  progress=None,
737
  )
738
  return {
739
- "first_audio_path": first,
740
- "second_audio_path": second,
741
- "audio_paths": paths,
742
  "generation_info": gen_info,
743
  "status_message": status_msg,
744
  "seed_value": seed_value,
@@ -1082,6 +1091,25 @@ def create_app() -> FastAPI:
1082
  "version": "1.0",
1083
  }
1084
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1085
  return app
1086
 
1087
 
 
280
  INITIAL_AVG_JOB_SECONDS = float(os.getenv("ACESTEP_AVG_JOB_SECONDS", "5.0"))
281
  AVG_WINDOW = int(os.getenv("ACESTEP_AVG_WINDOW", "50"))
282
 
283
+ def _path_to_audio_url(path: str) -> str:
284
+ """将本地文件路径转换为可下载的相对 URL"""
285
+ if not path:
286
+ return path
287
+ if path.startswith("http://") or path.startswith("https://"):
288
+ return path
289
+ encoded_path = urllib.parse.quote(path, safe="")
290
+ return f"/v1/audio?path={encoded_path}"
291
+
292
  @asynccontextmanager
293
  async def lifespan(app: FastAPI):
294
  # Clear proxy env that may affect downstream libs
 
745
  progress=None,
746
  )
747
  return {
748
+ "first_audio_path": _path_to_audio_url(first) if first else None,
749
+ "second_audio_path": _path_to_audio_url(second) if second else None,
750
+ "audio_paths": [_path_to_audio_url(p) for p in (paths or [])],
751
  "generation_info": gen_info,
752
  "status_message": status_msg,
753
  "seed_value": seed_value,
 
1091
  "version": "1.0",
1092
  }
1093
 
1094
+ @app.get("/v1/audio")
1095
+ async def get_audio(path: str):
1096
+ """Serve audio file by path."""
1097
+ from fastapi.responses import FileResponse
1098
+
1099
+ if not os.path.exists(path):
1100
+ raise HTTPException(status_code=404, detail=f"Audio file not found: {path}")
1101
+
1102
+ ext = os.path.splitext(path)[1].lower()
1103
+ media_types = {
1104
+ ".mp3": "audio/mpeg",
1105
+ ".wav": "audio/wav",
1106
+ ".flac": "audio/flac",
1107
+ ".ogg": "audio/ogg",
1108
+ }
1109
+ media_type = media_types.get(ext, "audio/mpeg")
1110
+
1111
+ return FileResponse(path, media_type=media_type)
1112
+
1113
  return app
1114
 
1115