-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaugmentation.py
More file actions
39 lines (26 loc) · 989 Bytes
/
Copy pathaugmentation.py
File metadata and controls
39 lines (26 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import numpy as nd
import random
from noise import noise, normalize
# adds N blank spectrogram / blank label tuples to dataset (D) for training silent
# input behavior
def add_silence_to_dataset(D, N):
c_ids = ''
for index in range(0, N):
D.append((nd.zeros((128, 128), dtype = nd.float32), c_ids))
return D
# add some randomly colored, randomly gained noise to add to a 1D audio file prior
# to running it through analysis methods. especially useful for silence training and
# data augmentation systems
def add_noise(y, passes=1):
N = len(y)
types = ['white', 'pink', 'blue', 'brown', 'violet']
n = nd.zeros(N)
# recursively generate and add noise to n |passes| times
for i in range(0, passes):
# select a random noise color algorithm to use
selected_type = random.randint(0, 4)
n += noise(N, color=types[selected_type]) / passes
n = normalize(n)
n *= nd.random.uniform(0, 0.20)
y += n
return y