feat(audiobook): change audio format from MP3 to WAV for project downloads and merging

This commit is contained in:
2026-03-10 17:56:46 +08:00
parent 006aa0c85f
commit bf7c73e57c
3 changed files with 24 additions and 14 deletions

View File

@@ -461,19 +461,19 @@ async def download_project(
if chapter is not None:
output_path = str(
Path(settings.OUTPUT_DIR) / "audiobook" / str(project_id) / "chapters" / f"chapter_{chapter}.mp3"
Path(settings.OUTPUT_DIR) / "audiobook" / str(project_id) / "chapters" / f"chapter_{chapter}.wav"
)
else:
output_path = str(
Path(settings.OUTPUT_DIR) / "audiobook" / str(project_id) / "full.mp3"
Path(settings.OUTPUT_DIR) / "audiobook" / str(project_id) / "full.wav"
)
if not Path(output_path).exists():
from core.audiobook_service import merge_audio_files
merge_audio_files(audio_paths, output_path)
filename = f"chapter_{chapter}.mp3" if chapter is not None else f"{project.title}.mp3"
return FileResponse(output_path, media_type="audio/mpeg", filename=filename)
filename = f"chapter_{chapter}.wav" if chapter is not None else f"{project.title}.wav"
return FileResponse(output_path, media_type="audio/wav", filename=filename)
@router.delete("/projects/{project_id}", status_code=status.HTTP_204_NO_CONTENT)

View File

@@ -542,4 +542,4 @@ def merge_audio_files(audio_paths: list[str], output_path: str) -> None:
if combined:
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
combined.export(output_path, format="mp3")
combined.export(output_path, format="wav")