<s> import cPickle as pickle <EOL> import numpy as np <EOL> import theano <EOL> from sparse_coding . sparse_coding_gammatone import gammatone_matrix , erb_space <EOL> def gen_phone ( mdl ) : <EOL> X = theano . tensor . dmatrix ( '<STR_LIT:X>' ) <EOL> P = theano . tensor . dmatrix ( '<STR_LIT:P>' ) <EOL> y = mdl . fprop ( [ X , P ] ) <EOL> predict = theano . function ( [ X , P ] , y ) <EOL> resolution = <NUM_LIT> <EOL> step = <NUM_LIT:64> <EOL> b = <NUM_LIT> <EOL> n_channels = <NUM_LIT:64> <EOL> D_multi = np . r_ [ tuple ( gammatone_matrix ( b , fc , resolution , step ) for <EOL> fc in erb_space ( <NUM_LIT> , <NUM_LIT> , n_channels ) ) ] <EOL> phones = np . load ( '<STR_LIT>' ) <EOL> X = np . asmatrix ( ( len ( phones ) , np . zeros ( <NUM_LIT> ) ) ) <EOL> phone_code = np . asmatrix ( ( len ( phones ) , np . zeros ( <NUM_LIT:3> * <NUM_LIT> ) ) ) <EOL> for pi , p in enumerate ( phones ) : <EOL> phone_code [ pi , [ p [ <NUM_LIT:0> ] , p [ <NUM_LIT:1> ] + <NUM_LIT> , p [ <NUM_LIT:2> ] + <NUM_LIT:2> * <NUM_LIT> ] ] = <NUM_LIT:1> <EOL> out = np . zeros ( <NUM_LIT> + <NUM_LIT:200> * ( len ( phones ) - <NUM_LIT:1> ) ) <EOL> step = <NUM_LIT:200> <EOL> for k in range ( <NUM_LIT:1> , len ( phones ) ) : <EOL> idx = range ( k * step , k * step + <NUM_LIT> ) <EOL> X [ k ] = predict ( X [ k - <NUM_LIT:1> ] , phone_code [ k ] ) <EOL> out [ idx ] += np . dot ( X [ k ] , D_multi ) <EOL> out_scaled = np . asarray ( out / max ( abs ( out ) ) , dtype = '<STR_LIT>' ) <EOL> return out_scaled <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from sys import argv <EOL> from scipy . io import wavfile <EOL> mdl = pickle . load ( open ( argv [ <NUM_LIT:1> ] ) ) <EOL> x0a = gen_phone ( mdl ) <EOL> wavfile . write ( argv [ <NUM_LIT:2> ] , <NUM_LIT> , out_scaled ) </s>
