I have a 5.1 or 7.1 audio in wav-file. What is the best way of converting this audio to stereo.
Test wav-files can be found here: https://www.jensign.com/bdp95/7dot1voiced/index.html
Currently i use the following code:
import librosa
import soundfile as sf
import numpy as np
audio, rate = librosa.load(input_file, sr=None, mono=False)
print(audio.shape)
if audio.shape[0] == 6:
# 5.1 audio
# Expected order Front Left, Front Right, Center, Low-frequency effects, Surround Left, Surround Right
audio_new = np.zeros((2, audio.shape[1]), dtype=np.float32)
audio_new[0] = audio[0] + audio[4] + audio[2] / 2 + audio[3] / 2
audio_new[1] = audio[1] + audio[5] + audio[2] / 2 + audio[3] / 2
print(audio_new.shape)
sf.write("stereo_from_5.1.wav", audio_new.T, rate, subtype="FLOAT")
if audio.shape[0] == 8:
# 7.1 audio
# Expected order 1 - L · 2 - R · 3 - C · 4- Lfe · 5- Ls (side) · 6- Rs (side) · 7- Bsl (rear) · 8- Bsr (rear)
audio_new = np.zeros((2, audio.shape[1]), dtype=np.float32)
audio_new[0] = audio[0] + audio[4] + audio[6] + audio[2] / 2 + audio[3] / 2
audio_new[1] = audio[1] + audio[5] + audio[7] + audio[2] / 2 + audio[3] / 2
print(audio_new.shape)
sf.write("stereo_from_7.1.wav", audio_new.T, rate, subtype="FLOAT")
May be there is better way?