Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing mono_check for inference #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions inference/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np

def mono_check(audio):
'''
Check whether the audio is mono since our system only support mono audio
:param audio: audio matrix with shape: channel x frames (numpy array or tensor)
:return: audio matrix with shape: 1 x frames
'''
if audio.shape[0] == 1:
return audio
# preprocess stereo
elif audio.shape[0] == 2:
audio = audio.sum(0)[None, :] / 2
# preprocess 5.1
elif audio.shape[0] == 6:
L = audio[0]
R = audio[1]
C = audio[2]
Ls = audio[4]
Rs = audio[5]
Lt = L + 0.707 * Ls + C * 0.707
Rt = R + 0.707 * Rs + C * 0.707
audio = np.divide(Lt + Rt, 2)[None, :]
else:
raise Exception("The input audio format is not currently support")
# To Do: add more channel support
return audio