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

Fix sections of MVDR #1989

Merged
merged 2 commits into from
Nov 5, 2021
Merged
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
48 changes: 24 additions & 24 deletions examples/tutorials/mvdr_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

######################################################################
# Overview
# ========
# --------
#
# This is a tutorial on how to apply MVDR beamforming by using `torchaudio <https://github.com/pytorch/audio>`__.
#
Expand All @@ -25,7 +25,7 @@

######################################################################
# Preparation
# ===========
# -----------
#
# First, we import the necessary packages and retrieve the data.
#
Expand Down Expand Up @@ -71,12 +71,12 @@

######################################################################
# Generate the Ideal Ratio Mask (IRM)
# ===================================
# -----------------------------------
#

######################################################################
# Loading audio data
# ------------------
# ~~~~~~~~~~~~~~~~~~
#

mix, sr = torchaudio.load('_assets/mix.wav')
Expand All @@ -100,7 +100,7 @@

######################################################################
# Compute STFT
# ------------
# ~~~~~~~~~~~~
#

stft = torchaudio.transforms.Spectrogram(
Expand All @@ -117,7 +117,7 @@

######################################################################
# Generate the Ideal Ratio Mask (IRM)
# -----------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# .. note::
# We found using the mask directly peforms better than using the
Expand All @@ -143,12 +143,12 @@ def get_irms(spec_clean, spec_noise, spec_mix):

######################################################################
# Apply MVDR
# ==========
# ----------
#

######################################################################
# Apply MVDR beamforming by using multi-channel masks
# ---------------------------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

results_multi = {}
Expand All @@ -160,7 +160,7 @@ def get_irms(spec_clean, spec_noise, spec_mix):

######################################################################
# Apply MVDR beamforming by using single-channel masks
# ----------------------------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# We use the 1st channel as an example.
# The channel selection may depend on the design of the microphone array
Expand All @@ -174,7 +174,7 @@ def get_irms(spec_clean, spec_noise, spec_mix):

######################################################################
# Compute Si-SDR scores
# ---------------------
# ~~~~~~~~~~~~~~~~~~~~~
#

def si_sdr(estimate, reference, epsilon=1e-8):
Expand All @@ -198,94 +198,94 @@ def si_sdr(estimate, reference, epsilon=1e-8):

######################################################################
# Results
# =======
# -------
#

######################################################################
# Single-channel mask results
# ---------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

for solution in results_single:
print(solution+": ", si_sdr(results_single[solution][None,...], reverb_clean[0:1]))

######################################################################
# Multi-channel mask results
# --------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
#

for solution in results_multi:
print(solution+": ", si_sdr(results_multi[solution][None,...], reverb_clean[0:1]))

######################################################################
# Original audio
# ==============
# --------------
#

######################################################################
# Mixture speech
# --------------
# ~~~~~~~~~~~~~~
#

ipd.Audio(mix[0], rate=16000)

######################################################################
# Noise
# -----
# ~~~~~
#

ipd.Audio(noise[0], rate=16000)

######################################################################
# Clean speech
# ------------
# ~~~~~~~~~~~~
#

ipd.Audio(clean[0], rate=16000)

######################################################################
# Enhanced audio
# ==============
# --------------
#

######################################################################
# Multi-channel mask, ref_channel solution
# ----------------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

ipd.Audio(results_multi['ref_channel'], rate=16000)

######################################################################
# Multi-channel mask, stv_evd solution
# ------------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

ipd.Audio(results_multi['stv_evd'], rate=16000)

######################################################################
# Multi-channel mask, stv_power solution
# --------------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

ipd.Audio(results_multi['stv_power'], rate=16000)

######################################################################
# Single-channel mask, ref_channel solution
# -----------------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

ipd.Audio(results_single['ref_channel'], rate=16000)

######################################################################
# Single-channel mask, stv_evd solution
# -------------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

ipd.Audio(results_single['stv_evd'], rate=16000)

######################################################################
# Single-channel mask, stv_power solution
# ---------------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

ipd.Audio(results_single['stv_power'], rate=16000)