gourxb
gourxb

Reputation: 325

how to convert a song as time varying wave in python and add noise to it and play it again?

I am trying to extract a feature from a song in python and plot it as a signal, then add random noise to it and play it back as a noisy signal. How can I do this?

I can do the following to extract the input_data from the song. What's the best way to proceed from here?

from scipy.io.wavfile import read
import matplotlib.pyplot as plt
input_data = read("Sample.wav")

Upvotes: 0

Views: 261

Answers (1)

James Kl
James Kl

Reputation: 187

Something like this should work

import librosa
import numpy as np
from IPython.display import Audio

song, sr = librosa.load('Song.mp3')

mu = 0;
sigma = 0.1 #you'll want to adjust sigma to adjust the noise level
noise = np.random.normal(mu,sigma,len(song))

distorted_song = song + noise
Audio(distorted_song, rate = sr)  

Upvotes: 1

Related Questions