Skip to content

Commit dce518c

Browse files
authored
convert nodes_audio.py to V3 schema (#10798)
1 parent 440268d commit dce518c

File tree

2 files changed

+387
-376
lines changed

2 files changed

+387
-376
lines changed

comfy_api/latest/_ui.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,10 @@ def save_audio(
319319
for key, value in metadata.items():
320320
output_container.metadata[key] = value
321321

322+
layout = "mono" if waveform.shape[0] == 1 else "stereo"
322323
# Set up the output stream with appropriate properties
323324
if format == "opus":
324-
out_stream = output_container.add_stream("libopus", rate=sample_rate)
325+
out_stream = output_container.add_stream("libopus", rate=sample_rate, layout=layout)
325326
if quality == "64k":
326327
out_stream.bit_rate = 64000
327328
elif quality == "96k":
@@ -333,7 +334,7 @@ def save_audio(
333334
elif quality == "320k":
334335
out_stream.bit_rate = 320000
335336
elif format == "mp3":
336-
out_stream = output_container.add_stream("libmp3lame", rate=sample_rate)
337+
out_stream = output_container.add_stream("libmp3lame", rate=sample_rate, layout=layout)
337338
if quality == "V0":
338339
# TODO i would really love to support V3 and V5 but there doesn't seem to be a way to set the qscale level, the property below is a bool
339340
out_stream.codec_context.qscale = 1
@@ -342,12 +343,12 @@ def save_audio(
342343
elif quality == "320k":
343344
out_stream.bit_rate = 320000
344345
else: # format == "flac":
345-
out_stream = output_container.add_stream("flac", rate=sample_rate)
346+
out_stream = output_container.add_stream("flac", rate=sample_rate, layout=layout)
346347

347348
frame = av.AudioFrame.from_ndarray(
348349
waveform.movedim(0, 1).reshape(1, -1).float().numpy(),
349350
format="flt",
350-
layout="mono" if waveform.shape[0] == 1 else "stereo",
351+
layout=layout,
351352
)
352353
frame.sample_rate = sample_rate
353354
frame.pts = 0

0 commit comments

Comments
 (0)