forked from fcakyon/segan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_loader.py
42 lines (36 loc) · 1.31 KB
/
data_loader.py
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
40
41
42
from __future__ import print_function
import tensorflow as tf
from ops import *
import numpy as np
def pre_emph(x, coeff=0.95):
x0 = tf.reshape(x[0], [1,])
diff = x[1:] - coeff * x[:-1]
concat = tf.concat([x0, diff],0)
return concat
def de_emph(y, coeff=0.95):
if coeff <= 0:
return y
x = np.zeros(y.shape[0], dtype=np.float32)
x[0] = y[0]
for n in range(1, y.shape[0], 1):
x[n] = coeff * x[n - 1] + y[n]
return x
def read_and_decode(filename_queue, canvas_size, preemph=0.):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
features={
'wav_raw': tf.FixedLenFeature([], tf.string),
'noisy_raw': tf.FixedLenFeature([], tf.string),
})
wave = tf.decode_raw(features['wav_raw'], tf.int32)
wave.set_shape(canvas_size)
wave = (2./65535.) * tf.cast((wave - 32767), tf.float32) + 1.
noisy = tf.decode_raw(features['noisy_raw'], tf.int32)
noisy.set_shape(canvas_size)
noisy = (2./65535.) * tf.cast((noisy - 32767), tf.float32) + 1.
if preemph > 0:
wave = tf.cast(pre_emph(wave, preemph), tf.float32)
noisy = tf.cast(pre_emph(noisy, preemph), tf.float32)
return wave, noisy