@@ -142,9 +142,10 @@ def save_audio(self, audio, filename_prefix="ComfyUI", format="flac", prompt=Non
142142        for  key , value  in  metadata .items ():
143143            output_container .metadata [key ] =  value 
144144
145+         layout  =  'mono'  if  waveform .shape [0 ] ==  1  else  'stereo' 
145146        # Set up the output stream with appropriate properties 
146147        if  format  ==  "opus" :
147-             out_stream  =  output_container .add_stream ("libopus" , rate = sample_rate )
148+             out_stream  =  output_container .add_stream ("libopus" , rate = sample_rate ,  layout = layout )
148149            if  quality  ==  "64k" :
149150                out_stream .bit_rate  =  64000 
150151            elif  quality  ==  "96k" :
@@ -156,7 +157,7 @@ def save_audio(self, audio, filename_prefix="ComfyUI", format="flac", prompt=Non
156157            elif  quality  ==  "320k" :
157158                out_stream .bit_rate  =  320000 
158159        elif  format  ==  "mp3" :
159-             out_stream  =  output_container .add_stream ("libmp3lame" , rate = sample_rate )
160+             out_stream  =  output_container .add_stream ("libmp3lame" , rate = sample_rate ,  layout = layout )
160161            if  quality  ==  "V0" :
161162                #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 
162163                out_stream .codec_context .qscale  =  1 
@@ -165,9 +166,9 @@ def save_audio(self, audio, filename_prefix="ComfyUI", format="flac", prompt=Non
165166            elif  quality  ==  "320k" :
166167                out_stream .bit_rate  =  320000 
167168        else : #format == "flac": 
168-             out_stream  =  output_container .add_stream ("flac" , rate = sample_rate )
169+             out_stream  =  output_container .add_stream ("flac" , rate = sample_rate ,  layout = layout )
169170
170-         frame  =  av .AudioFrame .from_ndarray (waveform .movedim (0 , 1 ).reshape (1 , - 1 ).float ().numpy (), format = 'flt' , layout = 'mono'   if   waveform . shape [ 0 ]  ==   1   else   'stereo' )
171+         frame  =  av .AudioFrame .from_ndarray (waveform .movedim (0 , 1 ).reshape (1 , - 1 ).float ().numpy (), format = 'flt' , layout = layout )
171172        frame .sample_rate  =  sample_rate 
172173        frame .pts  =  0 
173174        output_container .mux (out_stream .encode (frame ))
0 commit comments