Python audio data expansion
The classical deep learning network AlexNet uses Data Augmentation to expand the data set and achieve better classification results. In the field of deep learning images, data expansion is performed by means of translation, flipping, and noise addition. However, in the Audio field, how do you do data expansion?
Audio data expansion mainly includes the following four methods:
Audio Clip
Audio Rotation
Audio Tuning (Tune)
Audio Noise
Audio analysis is based on librosa audio libraries; matrix operations are based on scipy and numpy scientific computation libraries.
The following is the Python implementation
01
Audio trim
Import librosa
From scipy.io import wavfile y, sr = librosa.load("../data/love_illusion.mp3")
# read audio print y.shape, sr wavfile.write("../data/love_illusion_20s.mp3", sr, y[20 * sr:40 * sr])
# write audio
02
Audio rotation
Import cv2
Import librosa
From scipy.io import wavfile y, sr = librosa.load("../data/raw/love_illusion_20s.mp3")
# read audio ly = len(y) y_tune = cv2.resize(y, (1, int(len(y) * 1.2))).squeeze() lc = len(y_tune) - ly y_tune = y_tune[int( Lc / 2):int(lc / 2) + ly]print y.shape, sr wavfile.write("../data/raw/xxx_tune.mp3", sr, y_tune)
# write audio
03
Audio tuning
Import cv2
Import librosa
From scipy.io import wavfile y, sr = librosa.load("../data/raw/love_illusion_20s.mp3")
# read audio ly = len(y) y_tune = cv2.resize(y, (1, int(len(y) * 1.2))).squeeze() lc = len(y_tune) - ly y_tune = y_tune[int( Lc / 2):int(lc / 2) + ly]print y.shape, sr wavfile.write("../data/raw/xxx_tune.mp3", sr, y_tune)
# write audio
04
Audio noise
Import librosa
From scipy.io import wavfile
Import numpy as np
y, sr = librosa.load("../data/raw/love_illusion_20s.mp3")
# read audio wn = np.random.randn(len(y)) y = np.where(y != 0.0, y + 0.02 * wn, 0.0)
# Do not add noise to 0! Print y.shape, sr wavfile.write("../data/raw/love_illusion_20s_w.mp3", sr, y)
# write audio
The RIMA LFP series lithium battery is made of LiFePO4 cells, the battery has been designed and developed to provide a lighter, higher power and longer life solution to lead acid batteries. LiFePO4 batteries last longer and can produce 10 times the number of cycles than a typical lead acid battery. At only 40% of the weight of the equivalent lead acid battery, our LiFePO4 range is ideal for those applications that need to be lighter and more mobile but deliver the same power.
OREMA POWER CO., LTD. , https://www.oremabattery.com