#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_line_magic('load_ext', 'autoreload') get_ipython().run_line_magic('autoreload', '2') #%env CUDA_VISIBLE_DEVICES=3 # In[ ]: colab_requirements = [ "pip install librosa", "pip install noisereduce", "pip install soundfile", ] import sys, subprocess def run_subprocess_command(cmd): # run the command process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) # print the output for line in process.stdout: print(line.decode().strip()) IN_COLAB = "google.colab" in sys.modules if IN_COLAB: for i in colab_requirements: run_subprocess_command(i) # # Use torchgate directly as nn.module class # In[2]: import torch from noisereduce.torchgate import TorchGate as TG device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") # Create TorchGating instance tg = TG(sr=8000, nonstationary=True).to(device) # Apply Spectral Gate to noisy speech signal noisy_speech = torch.randn(3, 32000, device=device) enhanced_speech = tg(noisy_speech)