Add `export_to_wav` to `diffusers.utils` and use it in `diffusers serve` / `diffusers run`
メンテナーはふだん 1 日以内に返信
@DN6 がすでに取り組んでいます。
2026年11月20日 から。
評価
この issue はまだ評価されていません。
説明
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
- 主要言語
- Python
- スター
- 35k
- フォーク
- 7.5k
- 平均マージ
- 2日 22時間
- マージ済み PR(30日)
- 58
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
huggingface/diffusers のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
huggingface/diffusers#15436 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
InpaintProcessor crashes when padding_mask_crop is set and a dimension is omitted対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
huggingface/diffusers#15433 ·
メンテナーはふだん 1 日以内に返信
-
LTXEulerAncestralRFScheduler skips signal scaling with s_noise=0対応中かも @hparik11 が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
huggingface/diffusers#15423 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Docs: 13 docstrings document parameters their functions don't have対応中かも @M-Colley が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
huggingface/diffusers#15363 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
`ZImageImg2ImgPipeline` / `ZImageInpaintPipeline`: explicit height/width different from the input image raises RuntimeError対応中かも @chessing234 が 11 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
huggingface/diffusers#15337 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
huggingface/diffusers の issue をすべて見る
似ている issue
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
MakazhanAlpamys/Soup#3589 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
ClickHouse/clickhouse-connect#1266 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
biosustain/growthcurves_app#89 ·
メンテナーはふだん 1 日以内に返信
-
`LogProxyConsumer._on_relation_departed` raises `APIError` when the promtail service does not existオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
canonical/loki-k8s-operator#695 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信