def decompress_spectrum(self, COMPSPEC, spec_type, pp_mcep=False): if self.spec_type == 'fwbnd': SPEC = np.exp( sp.fwbnd2linbnd(COMPSPEC, self.fs, self.dftlen, smooth=True)) if pp_mcep: # pragma: no cover Would need SPTK to test it print(' Merlin/SPTK Post-proc on MCEP') import external.merlin.generate_pp mcep = sp.spec2mcep(SPEC * self.fs, sp.bark_alpha(self.fs), 256) # Arbitrary high order mcep_pp = external.merlin.generate_pp.mcep_postproc_sptk( mcep, self.fs, dftlen=self.dftlen) # Apply Merlin's post-proc on spec env SPEC = sp.mcep2spec(mcep_pp, sp.bark_alpha(self.fs), dftlen=self.dftlen) / self.fs elif self.spec_type == 'mcep': # pragma: no cover Would need SPTK to test it # TODO test if pp_mcep: print(' Merlin/SPTK Post-proc on MCEP') import external.merlin.generate_pp COMPSPEC = external.merlin.generate_pp.mcep_postproc_sptk( COMPSPEC, self.fs, dftlen=self.dftlen) # Apply Merlin's post-proc on spec env SPEC = sp.mcep2spec(COMPSPEC, sp.bark_alpha(self.fs), dftlen=self.dftlen) return SPEC
def synthesis(self, CMP, pp_mcep=False, pp_f0_smooth=None): if not pp_f0_smooth is None: raise ValueError( 'VocoderWORLD synthesis does not include an f0 smoother, please use `pp_f0_smooth=None`' ) import pyworld as pw f0 = CMP[:, 0] f0 = np.exp(f0) vuv = CMP[:, -1] f0[vuv < 0.5] = 0 SPEC = self.decompress_spectrum(CMP[:, 1:1 + self.spec_size], self.spec_type, pp_mcep=pp_mcep) APER = CMP[:, 1 + self.spec_size:1 + self.spec_size + self.aper_size] APER = sp.db2mag(APER) APER = sp.fwbnd2linbnd(APER, self.fs, self.dftlen) if 0: import matplotlib.pyplot as plt plt.ion() plt.subplot(311) plt.plot(f0) plt.xlim(0, len(f0)) plt.subplot(312) plt.imshow(sp.mag2db(SPEC).T, origin='lower', aspect='auto', interpolation='none', cmap='jet', vmin=-140, vmax=5) plt.subplot(313) plt.imshow(APER.T, origin='lower', aspect='auto', interpolation='none', cmap='jet', vmin=0, vmax=1) from IPython.core.debugger import Pdb Pdb().set_trace() syn = pw.synthesize(f0.astype('float64'), SPEC.astype('float64'), APER.astype('float64'), self.fs, self.shift * 1000.0) return syn
def synthesis(self, fs, CMP, pp_mcep=False): f0 = CMP[:, 0] f0 = np.exp(f0) SPEC = self.decompress_spectrum(CMP[:, 1:1 + self.spec_size], self.spec_type, pp_mcep=pp_mcep) NM = CMP[:, 1 + self.spec_size:1 + self.spec_size + self.nm_size] NM = sp.fwbnd2linbnd(NM, fs, self.dftlen) syn = pulsemodel.synthesis.synthesize( fs, np.vstack((self.shift * np.arange(len(f0)), f0)).T, SPEC, NM=NM, nm_cont=False, pp_atten1stharminsilences=-25) return syn