mirror of
https://github.com/xiph/opus.git
synced 2025-05-19 09:58:30 +00:00
decodes something...
This commit is contained in:
parent
638252a965
commit
5d8a1313d6
2 changed files with 19 additions and 10 deletions
|
@ -9,7 +9,7 @@ import numpy as np
|
||||||
import h5py
|
import h5py
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
rnn_units=64
|
rnn_units=512
|
||||||
pcm_bits = 8
|
pcm_bits = 8
|
||||||
pcm_levels = 2**pcm_bits
|
pcm_levels = 2**pcm_bits
|
||||||
nb_used_features = 37
|
nb_used_features = 37
|
||||||
|
@ -20,6 +20,7 @@ def new_wavernn_model():
|
||||||
pitch = Input(shape=(None, 1))
|
pitch = Input(shape=(None, 1))
|
||||||
feat = Input(shape=(None, nb_used_features))
|
feat = Input(shape=(None, nb_used_features))
|
||||||
dec_feat = Input(shape=(None, 32))
|
dec_feat = Input(shape=(None, 32))
|
||||||
|
dec_state = Input(shape=(rnn_units,))
|
||||||
|
|
||||||
conv1 = Conv1D(16, 7, padding='causal')
|
conv1 = Conv1D(16, 7, padding='causal')
|
||||||
pconv1 = Conv1D(16, 5, padding='same')
|
pconv1 = Conv1D(16, 5, padding='same')
|
||||||
|
@ -48,8 +49,8 @@ def new_wavernn_model():
|
||||||
encoder = Model(feat, cfeat)
|
encoder = Model(feat, cfeat)
|
||||||
|
|
||||||
dec_rnn_in = Concatenate()([cpcm, cpitch, dec_feat])
|
dec_rnn_in = Concatenate()([cpcm, cpitch, dec_feat])
|
||||||
dec_gru_out, state = rnn(dec_rnn_in)
|
dec_gru_out, state = rnn(dec_rnn_in, initial_state=dec_state)
|
||||||
dec_ulaw_prob = md(dec_gru_out)
|
dec_ulaw_prob = md(dec_gru_out)
|
||||||
|
|
||||||
decoder = Model([pcm, pitch, dec_feat], [dec_ulaw_prob, state])
|
decoder = Model([pcm, pitch, dec_feat, dec_state], [dec_ulaw_prob, state])
|
||||||
return model, encoder, decoder
|
return model, encoder, decoder
|
||||||
|
|
|
@ -21,7 +21,7 @@ batch_size = 64
|
||||||
|
|
||||||
model, enc, dec = lpcnet.new_wavernn_model()
|
model, enc, dec = lpcnet.new_wavernn_model()
|
||||||
model.compile(optimizer=Adadiff(), loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])
|
model.compile(optimizer=Adadiff(), loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])
|
||||||
model.summary()
|
#model.summary()
|
||||||
|
|
||||||
pcmfile = sys.argv[1]
|
pcmfile = sys.argv[1]
|
||||||
feature_file = sys.argv[2]
|
feature_file = sys.argv[2]
|
||||||
|
@ -47,14 +47,15 @@ in_data = np.reshape(in_data, (nb_frames*pcm_chunk_size, 1))
|
||||||
out_data = np.reshape(data, (nb_frames*pcm_chunk_size, 1))
|
out_data = np.reshape(data, (nb_frames*pcm_chunk_size, 1))
|
||||||
|
|
||||||
|
|
||||||
model.load_weights('lpcnet1h_30.h5')
|
model.load_weights('lpcnet1i_30.h5')
|
||||||
|
|
||||||
order = 16
|
order = 16
|
||||||
|
|
||||||
pcm = 0.*out_data
|
pcm = 0.*out_data
|
||||||
exc = 0.*out_data
|
exc = out_data-0
|
||||||
pitch = np.zeros((1, 1, 1), dtype='float32')
|
pitch = np.zeros((1, 1, 1), dtype='float32')
|
||||||
iexc = np.zeros((1, 1, 1), dtype='float32')
|
fexc = np.zeros((1, 1, 1), dtype='float32')
|
||||||
|
iexc = np.zeros((1, 1, 1), dtype='int16')
|
||||||
state = np.zeros((1, lpcnet.rnn_units), dtype='float32')
|
state = np.zeros((1, lpcnet.rnn_units), dtype='float32')
|
||||||
for c in range(1, nb_frames):
|
for c in range(1, nb_frames):
|
||||||
cfeat = enc.predict(features[c:c+1, :, :nb_used_features])
|
cfeat = enc.predict(features[c:c+1, :, :nb_used_features])
|
||||||
|
@ -68,7 +69,14 @@ for c in range(1, nb_frames):
|
||||||
period = period - 4
|
period = period - 4
|
||||||
for i in range(frame_size):
|
for i in range(frame_size):
|
||||||
pitch[0, 0, 0] = exc[f*frame_size + i - period, 0]
|
pitch[0, 0, 0] = exc[f*frame_size + i - period, 0]
|
||||||
#p, state = dec.predict([
|
fexc[0, 0, 0] = exc[f*frame_size + i - 1]
|
||||||
pcm[f*frame_size + i, 0] = gain*out_data[f*frame_size + i, 0] - sum(a*pcm[f*frame_size + i - 1:f*frame_size + i - order-1:-1, 0])
|
#print(cfeat.shape)
|
||||||
print(pcm[f*frame_size + i, 0])
|
p, state = dec.predict([fexc, pitch, cfeat[:, fr:fr+1, :], state])
|
||||||
|
p = p/(1e-5 + np.sum(p))
|
||||||
|
#print(np.sum(p))
|
||||||
|
iexc[0, 0, 0] = np.argmax(np.random.multinomial(1, p[0,0,:], 1))-128
|
||||||
|
exc[f*frame_size + i] = iexc[0, 0, 0]/16.
|
||||||
|
#out_data[f*frame_size + i, 0] = iexc[0, 0, 0]
|
||||||
|
pcm[f*frame_size + i, 0] = gain*iexc[0, 0, 0] - sum(a*pcm[f*frame_size + i - 1:f*frame_size + i - order-1:-1, 0])
|
||||||
|
print(iexc[0, 0, 0], out_data[f*frame_size + i, 0], pcm[f*frame_size + i, 0])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue