fix: handle Seed-VC audio array shape

This commit is contained in:
Azimkin
2026-04-08 14:05:21 +02:00
parent 7ecb9941e9
commit 2b93fea7ca

View File

@@ -123,6 +123,31 @@ class SeedVCService:
# Determine sample rate based on f0_condition
sr = 44100 if f0_condition else 22050
# Fix audio array shape for soundfile.write()
# Seed-VC may return array with different shapes that need adjustment
if isinstance(audio_array, tuple):
# If wrapper returns tuple, extract the array
audio_array = audio_array[0]
# Ensure numpy array
audio_array = np.asarray(audio_array)
# Handle shape issues
if len(audio_array.shape) == 1:
# Mono audio, shape is (samples,) - already correct
pass
elif len(audio_array.shape) == 2:
# Could be (channels, samples) or (samples, channels)
if audio_array.shape[0] < audio_array.shape[1]:
# Shape is (channels, samples), take first channel
audio_array = audio_array[0]
else:
# Shape is (samples, channels), take first channel
audio_array = audio_array[:, 0]
# Ensure float32 format for soundfile
audio_array = audio_array.astype(np.float32)
# Save output
sf.write(output_path, audio_array, sr)
logger.info(f"Voice conversion complete: {output_path}")