Add `export_to_wav` to `diffusers.utils` and use it in `diffusers serve` / `diffusers run`
Maintainer antworten meist innerhalb von 1 Tag
@DN6 arbeitet bereits daran.
Seit 20.11.2026.
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
Context
#15017 (diffusers serve) has this TODO in src/diffusers/commands/serve/backends.py, in the audio branch of the output encoding:
# TODO(DN6): write the files with `export_to_wav` once it is added to `diffusers.utils`.
for index, audio in enumerate(arrays):
data = np.asarray(audio)
if data.dtype.kind == "f":
data = (np.clip(data, -1.0, 1.0) * 32767).astype(np.int16)
else:
data = data.astype(np.int16)
# `wave` takes interleaved samples x channels; the shorter axis is taken to be the channels.
if data.ndim == 1:
data = data[:, None]
elif data.shape[0] < data.shape[1]:
data = data.T
filename = f"{name}-{index}.wav"
with wave.open(str(generation.directory / filename), "wb") as file:
...
diffusers.utils.export_utils already has export_to_gif, export_to_ply, export_to_obj and export_to_video, but nothing for audio. Because of that, WAV writing is now implemented by hand in at least two places:
src/diffusers/commands/run.py:_save_audios(onmain), which writes 16-bit PCM WAV with the stdlibwavemodulesrc/diffusers/commands/serve/backends.py(#15017): a near-copy of the same logic
The audio pipeline docstrings (AudioLDM, AudioLDM2, MusicLDM, Dance Diffusion) also tell users to call scipy.io.wavfile.write themselves.
Proposal
Add export_to_wav to diffusers/utils/export_utils.py and export it from diffusers.utils, following the existing export_to_* helpers. Roughly:
def export_to_wav(
audio: np.ndarray | torch.Tensor,
output_wav_path: str | None = None,
sample_rate: int = 16000,
) -> str:
...
- Accepts numpy arrays or torch tensors (converted with
.detach().float().cpu().numpy()) - Float input is clipped to [-1, 1] and converted to int16. Integer input is cast to int16.
- 1D input is treated as mono. For 2D input, the shorter axis is treated as channels and transposed to samples × channels if needed (same heuristic used today).
- Uses the stdlib
wavemodule, so it adds no scipy dependency - If
output_wav_pathis not given, writes to a temp file (same as the otherexport_to_*helpers) and returns the path
Follow-ups
- Replace the TODO in
commands/serve/backends.pywith a call toexport_to_wav - Make
_save_audiosincommands/run.pyuse it too - Optionally, update the audio pipeline docstring examples to use
export_to_wavinstead ofscipy.io.wavfile.write - Add a small unit test covering mono/stereo layouts and float/int inputs
Requested by Sayak Paul - Slack thread - Agent trace
- Vorherrschende Sprache
- Python
- Sterne
- 35k
- Forks
- 7.5k
- Ø Merge
- 2 T. 22 Std.
- Gemergte PRs (30 T.)
- 58
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus huggingface/diffusers
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
huggingface/diffusers#15436 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
InpaintProcessor crashes when padding_mask_crop is set and a dimension is omittedEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
huggingface/diffusers#15433 ·
Maintainer antworten meist innerhalb von 1 Tag
-
LTXEulerAncestralRFScheduler skips signal scaling with s_noise=0Evtl. vergeben @hparik11 hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
huggingface/diffusers#15423 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Docs: 13 docstrings document parameters their functions don't haveEvtl. vergeben @M-Colley hat das vor 3 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
huggingface/diffusers#15363 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
`ZImageImg2ImgPipeline` / `ZImageInpaintPipeline`: explicit height/width different from the input image raises RuntimeErrorEvtl. vergeben @chessing234 hat das vor 11 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
huggingface/diffusers#15337 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in huggingface/diffusers
Ähnliche Issues
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount dueEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 79/100
developmentseed/titiler-covjson#164 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
awslabs/visual-asset-management-system#2164 ·
Maintainer antworten meist innerhalb von 1 Tag
-
needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
MakazhanAlpamys/Soup#3589 ·
Maintainer antworten meist innerhalb von 1 Tag
-
channels status reports the wrong Enabled value for Feishu instances and default-enabled WebSocketOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
Maintainer antworten meist innerhalb von 1 Tag