{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "b96abe95", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "#%env CUDA_VISIBLE_DEVICES=3" ] }, { "cell_type": "code", "execution_count": null, "id": "304d7eca", "metadata": {}, "outputs": [], "source": [ "colab_requirements = [\n", " \"pip install librosa\",\n", " \"pip install noisereduce\",\n", " \"pip install soundfile\",\n", "\n", "]\n", "\n", "import sys, subprocess\n", "\n", "def run_subprocess_command(cmd):\n", " # run the command\n", " process = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)\n", " # print the output\n", " for line in process.stdout:\n", " print(line.decode().strip())\n", "\n", "IN_COLAB = \"google.colab\" in sys.modules\n", "if IN_COLAB:\n", " for i in colab_requirements:\n", " run_subprocess_command(i)" ] }, { "cell_type": "markdown", "id": "c8e4f1f0", "metadata": {}, "source": [ "# Use torchgate directly as nn.module class" ] }, { "cell_type": "code", "execution_count": 2, "id": "a0093f8e", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\zorea\\.conda\\envs\\ml\\lib\\site-packages\\noisereduce-3.0.0-py3.10.egg\\noisereduce\\torchgate\\torchgate.py:180: UserWarning: Using padding='same' with even kernel lengths and odd dilation may require a zero-padded copy of the input be created (Triggered internally at C:\\cb\\pytorch_1000000000000\\work\\aten\\src\\ATen\\native\\Convolution.cpp:1004.)\n" ] } ], "source": [ "import torch\n", "from noisereduce.torchgate import TorchGate as TG\n", "device = torch.device(\"cuda\") if torch.cuda.is_available() else torch.device(\"cpu\")\n", "\n", "# Create TorchGating instance\n", "tg = TG(sr=8000, nonstationary=True).to(device)\n", "\n", "# Apply Spectral Gate to noisy speech signal\n", "noisy_speech = torch.randn(3, 32000, device=device)\n", "enhanced_speech = tg(noisy_speech)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.11" } }, "nbformat": 4, "nbformat_minor": 5 }