Commit fd102e22 authored by Niyas Inshaf's avatar Niyas Inshaf

Upload New File

parent cbb7209a
# -*- coding: utf-8 -*-
"""Untitled16.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1YZOFDlzEhI9HUk0TBJ3M5opmNvLCqb8x
"""
# Commented out IPython magic to ensure Python compatibility.
# %load_ext autoreload
# %autoreload 2
#%env CUDA_VISIBLE_DEVICES=3
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)
# Commented out IPython magic to ensure Python compatibility.
import IPython
from scipy.io import wavfile
import noisereduce as nr
import soundfile as sf
from noisereduce.generate_noise import band_limited_noise
import matplotlib.pyplot as plt
import urllib.request
import numpy as np
import io
# %matplotlib inline
url = "https://raw.githubusercontent.com/timsainb/noisereduce/master/assets/fish.wav"
response = urllib.request.urlopen(url)
data, rate = sf.read(io.BytesIO(response.read()))
data = data
IPython.display.Audio(data=data, rate=rate)
fig, ax = plt.subplots(figsize=(20,3))
ax.plot(data)
noise_len = 2 # seconds
noise = band_limited_noise(min_freq=2000, max_freq = 12000, samples=len(data), samplerate=rate)*10
noise_clip = noise[:rate*noise_len]
audio_clip_band_limited = data+noise
fig, ax = plt.subplots(figsize=(20,3))
ax.plot(audio_clip_band_limited)
IPython.display.Audio(data=audio_clip_band_limited, rate=rate)
reduced_noise = nr.reduce_noise(y = audio_clip_band_limited, sr=rate, n_std_thresh_stationary=1.5,stationary=True)
fig, ax = plt.subplots(figsize=(20,3))
ax.plot(reduced_noise)
IPython.display.Audio(data=reduced_noise, rate=rate)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment