mirror of
https://github.com/xiph/opus.git
synced 2025-05-18 09:28:30 +00:00
audio-domain synthesis
This commit is contained in:
parent
4cf2b2705a
commit
70789e6f43
4 changed files with 138 additions and 3 deletions
|
@ -4,6 +4,7 @@ import math
|
|||
from keras.models import Model
|
||||
from keras.layers import Input, LSTM, CuDNNGRU, Dense, Embedding, Reshape, Concatenate, Lambda, Conv1D, Multiply, Bidirectional, MaxPooling1D, Activation
|
||||
from keras import backend as K
|
||||
from keras.initializers import Initializer
|
||||
from mdense import MDense
|
||||
import numpy as np
|
||||
import h5py
|
||||
|
@ -14,6 +15,30 @@ pcm_bits = 8
|
|||
pcm_levels = 2**pcm_bits
|
||||
nb_used_features = 38
|
||||
|
||||
class PCMInit(Initializer):
|
||||
def __init__(self, gain=.1, seed=None):
|
||||
self.gain = gain
|
||||
self.seed = seed
|
||||
|
||||
def __call__(self, shape, dtype=None):
|
||||
num_rows = 1
|
||||
for dim in shape[:-1]:
|
||||
num_rows *= dim
|
||||
num_cols = shape[-1]
|
||||
flat_shape = (num_rows, num_cols)
|
||||
if self.seed is not None:
|
||||
np.random.seed(self.seed)
|
||||
a = np.random.uniform(-1.7321, 1.7321, flat_shape)
|
||||
#a[:,0] = math.sqrt(12)*np.arange(-.5*num_rows+.5,.5*num_rows-.4)/num_rows
|
||||
#a[:,1] = .5*a[:,0]*a[:,0]*a[:,0]
|
||||
a = a + np.reshape(math.sqrt(12)*np.arange(-.5*num_rows+.5,.5*num_rows-.4)/num_rows, (num_rows, 1))
|
||||
return self.gain * a
|
||||
|
||||
def get_config(self):
|
||||
return {
|
||||
'gain': self.gain,
|
||||
'seed': self.seed
|
||||
}
|
||||
|
||||
def new_wavernn_model():
|
||||
pcm = Input(shape=(None, 1))
|
||||
|
@ -35,6 +60,10 @@ def new_wavernn_model():
|
|||
cpcm = pcm
|
||||
cpitch = pitch
|
||||
|
||||
embed = Embedding(256, 128, embeddings_initializer=PCMInit())
|
||||
cpcm = Reshape((-1, 128))(embed(pcm))
|
||||
|
||||
|
||||
cfeat = fconv2(fconv1(feat))
|
||||
|
||||
rep = Lambda(lambda x: K.repeat_elements(x, 160, 1))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue