Views
No views yet
facebook/sam-audio-large using mlx-audio version 0.2.10.
Refer to the original model card for more details on the model.pip install -U mlx-audio1from mlx_audio.sts import SAMAudio, SAMAudioProcessor, save_audio
2import mlx.core as mx
3
4# Load model and processor
5processor = SAMAudioProcessor.from_pretrained("facebook/sam-audio-large")
6model = SAMAudio.from_pretrained("facebook/sam-audio-large")
7
8# Process inputs
9batch = processor(
10 descriptions=["speech"],
11 audios=["path/to/audio.mp3"],
12 # anchors=[[("+", 0.2, 0.5)]], # Optional: temporal
13)
14
15# Separate audio
16result = model.separate(
17 audios=batch.audios,
18 descriptions=batch.descriptions,
19 sizes=batch.sizes,
20 anchor_ids=batch.anchor_ids,
21 anchor_alignment=batch.anchor_alignment,
22 ode_decode_chunk_size=50, # Chunked decoding for memory efficiency
23)
24
25# For long audio files, use separate_long().
26# Note: This is slower than separate() but it is more memory efficient.
27# result = model.separate_long(
28# audios=batch.audios,
29# descriptions=batch.descriptions,
30# chunk_seconds=10.0,
31# overlap_seconds=3.0,
32# anchor_ids=batch.anchor_ids,
33# anchor_alignment=batch.anchor_alignment,
34# ode_decode_chunk_size=50, # Chunked decoding for memory efficiency
35# )
36
37# Save output
38## Isolated speech
39save_audio(result.target[0], "separated.wav", sample_rate=model.sample_rate)
40
41## Residual audio (background music/noise/other sounds)
42save_audio(result.residual[0], "residual.wav", sample_rate=model.sample_rate)
43
44# Check memory usage
45print(f"Peak memory: {result.peak_memory:.2f} GB")