コード例 #1
0
 def extract(self):
     Features.extract(self)
     self._hop = 1 if self._hop is None else self._hop
     window, hop = self._window, self._hop
     if window and hop is not None:
         fp = self.feature_params
         num_frames = int(
             (window * fp['sample_rate']) / (1000.0 * fp['nhop']))
         num_hop = int((hop * fp['sample_rate']) / (1000.0 * fp['nhop']))
         print(num_frames, num_hop)
         if not num_frames and num_hop:
             raise ValueError(
                 "num_frames and num_hop too small for FFT window / hop")
         else:
             Y = []
             for k in range(0, self.X.shape[1] - window + 1, num_hop):
                 X = log(
                     self.X[:, np.arange(k, k + num_frames)] +
                     np.finfo(np.float32).eps
                 ) if self._log else self.X[:,
                                            np.arange(k, k + num_frames)]
                 Y.append(
                     np.fft.fftshift(np.absolute(np.fft.fft2(X))).flatten())
             self.X = np.array(Y)
     else:
         self.X = log(self.X +
                      np.finfo(np.float32).eps) if self._log else self.X
         self.X = np.fft.fftshift(np.absolute(np.fft.fft2(self.X)))
コード例 #2
0
    def __init__(self, model_file, feature_file, preprocess_file, wav_file, 
                 vocoder, queue):
        # The current models have a front end where there is a rectangular
        # window applied to the analysis window and a hamming window applied to
        # the synthesis window. The order should be reversed. The models
        # were potentially unnecessarily learning to spurious high frequency
        # content. This will be updated here when the models are updated
        with open(feature_file, 'r') as f:
            feat = cPickle.load(f)
            self.feat = feat['feature']
            if self.feat == 'cqft':
                self.Q = Features(np.array([]), feat).Q
            self.nfft = feat['nfft']
            self.wfft = feat['wfft']
            self.nhop = feat['nhop']
            self.sample_rate = feat['sample_rate']
            print("{0}\t{1}\t{2}".format(self.nfft,self.wfft,self.nhop))
        self.nolap = self.nfft-self.nhop
        self.win = np.hanning(self.wfft+1)[:-1]
        self.buf = np.zeros(self.nhop)
        self.olap_buf = np.zeros(self.nolap)

        self.queue = queue

        self.model_file = model_file
        self.init_model()

        self.p = pyaudio.PyAudio()
        self.is_processing = 0
        if wav_file is not None:
            self.source = "file"
            self.wav_file = wav_file
            self.wf = wave.open(wav_file, 'rb')
            if self.wf.getframerate() != self.sample_rate:
                warnings.warn("The audio file sample rate does not match the"+
                        "sample_rate of the models")
            channels = self.wf.getnchannels()
            assert(channels==1)
            format = self.p.get_format_from_width(self.wf.getsampwidth())
            input = False
        else:
            self.source = "line_in"
            channels = 1
            format = pyaudio.paInt16
            input = True
            self.m_buff = np.zeros(self.wfft)
        self.stream = self.p.open(rate=self.sample_rate,
                                  channels=channels,
                                  format=format,
                                  input=input,
                                  output=True,
                                  frames_per_buffer=self.nhop,
                                  start=False)
        with open(preprocess_file, 'r') as f:
            self.preprocess = cPickle.load(f)


        ##### The following patch should be removed at some point ######
        if isinstance(self.preprocess, 
                      pylearn2.datasets.preprocessing.Standardize):
            self.preprocess.invert = types.MethodType(icmc.Standardize.invert,
                                                      self.preprocess)
            self.preprocess.__class__ = icmc.Standardize

        if isinstance(self.preprocess, icmc.Pipeline):
            self.preprocess.invert = types.MethodType(icmc.Pipeline.invert, 
                                                      self.preprocess)
            for item in self.preprocess.items:
                if isinstance(item, 
                              pylearn2.datasets.preprocessing.Standardize):
                    item.invert = types.MethodType(icmc.Standardize.invert,
                                                   item)
                    item.__class__ = icmc.Standardize
        ################################################################
        if vocoder:
            self.dphi = (2 * np.pi * self.nhop * 
                         np.arange(self.nfft/2+1)) / self.nfft
            self.phase = np.random.rand(self.nfft/2+1) * 2 * np.pi - np.pi
        self.vocoder = vocoder
        self.playing = False
        self.run()
コード例 #3
0
 def __init__(self, arg, window=None, hop=None, logscale=False, **kwargs):
     kwargs['feature'] = 'cqft'
     self._window, self._hop, self._log = window, hop, logscale
     Features.__init__(self, arg, kwargs)
コード例 #4
0
 def extract(self):
     Features.extract(self)
     self.X = P.sqrt((P.diff(self.X)**2).sum(0)) / self.X.shape[0]
コード例 #5
0
 def __init__(self, arg, **kwargs):
     kwargs['feature'] = 'lcqft'
     Features.__init__(self, arg, kwargs)
コード例 #6
0
 def extract(self):
     Features.extract(self)
     mf = (self.X.T * self._logfrqs).sum(1) / self.X.T.sum(1)
     self.X = (((self.X / self.X.T.sum(1)).T *
                ((P.atleast_2d(self._logfrqs).T - mf)).T)**2).sum(1)
コード例 #7
0
 def extract(self):
     Features.extract(self)
     self.X = (self.X.T * self._logfrqs).sum(1) / self.X.T.sum(1)
コード例 #8
0
 def __init__(self, arg=None, **feature_params):
     feature_params['feature'] = 'power'
     feature_params['mantitude'] = False
     feature_params['log10'] = True
     Features.__init__(self, arg, feature_params)
コード例 #9
0
 def __init__(self, arg=None, **feature_params):
     feature_params['feature'] = 'hcqft'
     Features.__init__(self, arg, feature_params)