Skip to content
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ ACESTEP_LM_BACKEND=vllm
#
# Default: auto (based on GPU VRAM detection)
ACESTEP_INIT_LLM=auto
# Force all audio exports to FLAC as a workaround for torchcodec/FFmpeg
# load failures on some cloud GPU environments (Lightning AI, Lambda, etc.)
# Leave unset or =0 to respect the format chosen in the UI
# ACESTEP_FORCE_FLAC_EXPORT=0

# ==================== Model Storage ====================
# Shared checkpoints directory (useful when running multiple installations)
Expand Down Expand Up @@ -81,4 +85,4 @@ ACESTEP_INIT_LLM=auto
# ==================== Startup Settings ====================
# By default models are lazy-loaded on first request (fast server startup).
# Set to false to force eager model loading at startup.
# ACESTEP_NO_INIT=true
# ACESTEP_NO_INIT=true
8 changes: 7 additions & 1 deletion acestep/audio_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ def save_audio(
Actual saved file path
"""
format = (format or self.default_format).lower()

force_flac = os.getenv("ACESTEP_FORCE_FLAC_EXPORT", "0") == "1"
if force_flac:
format = "flac"
Comment on lines +219 to +221
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Forced FLAC can produce extension/content mismatch (e.g., .mp3 file containing FLAC).

At Line 221, format is forced to "flac", but if output_path already has .mp3/.wav (Line 233), suffix normalization won’t rewrite it. With upstream callers prebuilding names from requested format, this can save FLAC bytes under non-FLAC extensions.

Proposed fix
         force_flac = os.getenv("ACESTEP_FORCE_FLAC_EXPORT", "0") == "1"
         if force_flac:
-            format = "flac" 
+            format = "flac"

         # Ensure output path has correct extension
         output_path = Path(output_path)
+        if force_flac and output_path.suffix.lower() != ".flac":
+            output_path = output_path.with_suffix(".flac")

Also applies to: 228-240

🧰 Tools
🪛 Ruff (0.15.9)

[error] 222-222: Variable format is shadowing a Python builtin

(A001)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@acestep/audio_utils.py` around lines 220 - 222, The current force_flac branch
sets format = "flac" but leaves output_path's filename/extension unchanged,
causing extension/content mismatches; when ACESTEP_FORCE_FLAC_EXPORT is "1"
(force_flac), update output_path to match the forced format (e.g., use
pathlib.Path(output_path).with_suffix(f".{format}") or rebuild the filename from
format) and ensure any downstream suffix normalization logic (the block around
output_path and its suffix handling) uses the updated format so saved bytes and
file extension are consistent; reference the force_flac variable, format
assignment, and output_path handling in your change.

if format not in ["flac", "wav", "mp3", "wav32", "opus", "aac"]:
logger.warning(f"Unsupported format {format}, using {self.default_format}")
format = self.default_format
Expand Down Expand Up @@ -308,8 +312,10 @@ def save_audio(
str(output_path),
audio_tensor,
sample_rate,
channels_first=True,
channels_first=channels_first,
#backend="soundfile" #safe dependency
)


logger.debug(f"[AudioSaver] Saved audio to {output_path} ({format}, {sample_rate}Hz)")
return str(output_path)
Expand Down
14 changes: 13 additions & 1 deletion docs/en/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,19 @@ chmod +x start_gradio_ui.sh start_api_server.sh
# Launch REST API Server
./start_api_server.sh
```

> [!IMPORTANT]
> **Cloud GPU Users (Lightning AI, Lambda, etc.):**
> To prevent audio export crashes (`libtorchcodec` or `libavutil` errors), install the required system packages **before** running the app:
>
> ```bash
> sudo apt-get update && sudo apt-get install -y ffmpeg libavdevice60 libavcodec-extra
> ```
>
> If you still see torchcodec / FFmpeg load errors, export `LD_LIBRARY_PATH` in the same shell that launches the app:
>
> ```bash
> export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
> ```
> **Note:** Git must be installed via your system package manager (`sudo apt install git`, `sudo yum install git`, `sudo pacman -S git`).

### macOS (Apple Silicon / MLX)
Expand Down