除了模型結構和超參數,數據是值得重視的。
因爲垃圾進,垃圾出。
數據量不夠是常見的問題,使用數據增強的方式產生合成新數據,從某種程度上可以提高模型的泛化能力。
這裏介紹一些基本的音頻信號增強方法。
語音增強方法
添加噪聲(noise injection),時間平移(shifting time), 改變音高和速度(changing pitch and speed).
使用Numpy添加噪聲和時間平移;
使用librosa修改pitch和speed;
noise injection
import numpy as np
def manipulate(data, noise_factor):
noise = np.random.randn(len(data))
augmented_data = data + noise_factor * noise
# Cast back to same data type
augmented_data = augmented_data.astype(type(data[0]))
return augmented_data
Shifting Time
向左右平移數秒,右平移在左邊填0,左平移在右邊填0.
import numpy as np
def manipulate(data, sampling_rate, shift_max, shift_direction):
shift = np.random.randint(sampling_rate * shift_max)
if shift_direction == 'right':
shift = -shift
elif self.shift_direction == 'both':
direction = np.random.randint(0, 2)
if direction == 1:
shift = -shift
augmented_data = np.roll(data, shift)
# Set to silence for heading/ tailing
if shift > 0:
augmented_data[:shift] = 0
else:
augmented_data[shift:] = 0
return augmented_data
Changing Pitch
隨機修改音高
import librosa
def manipulate(data, sampling_rate, pitch_factor):
return librosa.effects.pitch_shift(data, sampling_rate, pitch_factor)
Changing Speed
修改速度
import librosa
def manipulate(data, speed_factor):
return librosa.effects.time_stretch(data, speed_factor)
譯自:Data Augmentation for Audio
作者: Edward Ma
原文鏈接:https://medium.com/@makcedward/data-augmentation-for-audio-76912b01fdf6