def synt_from_mcep_matrix_to_spec(f0, mcep_mat, aperiod_mat): world = World(samplingrate, float(hop_length) / samplingrate * 1000) fft_size = world.fftsize() spec_from_mcep = mcep2spec_from_matrix(mcep_mat, alpha, fft_size) out = world.synthesis(f0, spec_from_mcep, aperiod_mat) return out
def get_spec_coefs(fname, w=False): signal, samplingrate, _ = waveread(fname) world = World(samplingrate, float(hop_length) / samplingrate * 1000) f0, spec_mat, aperiod_mat = world.analyze(signal) if w: return world, f0, spec_mat, aperiod_mat else: return f0, spec_mat, aperiod_mat
def setUp(self): signal, samplingrate, _ = waveread("test/cmu_arctic/arctic_a0001.wav") self.world = World(samplingrate) self.alpha = estimate_alpha(samplingrate) self.samplingrate = samplingrate self.signal = signal self.f0, self.spec_mat, _ = self.world.analyze(signal) self.ep = ExcitePulse(16000, 80, False) self.order = 24
def test_from_matrix(self): world = World(self.samplingrate) _, spec, _ = world.analyze(self.signal) mcepmat = spec2mcep_from_matrix(spec, 20, self.alpha) mcep = spec2mcep(spec[300], 20, self.alpha) assert (mcep == mcepmat[300]).all() specmat = mcep2spec_from_matrix(mcepmat, self.alpha, self.windowsize) spec = mcep2spec(mcep, self.alpha, self.windowsize) assert (spec == specmat[300]).all()
def get_mcep_from_spec_mats(fname): # signal, samplingrate, _ = waveread(fname) samplingrate, signal = wavfile.read(fname) # print(signal.dtype) world = World(samplingrate, float(hop_length) / samplingrate * 1000) f0, spec_mat, aperiod_mat = world.analyze(np.float64(signal)) mcep_mat = spec2mcep_from_matrix(spec_mat, order, alpha) return f0, mcep_mat, aperiod_mat
class WorldTest(TestCase): def setUp(self): signal, samplingrate, _ = waveread("test/cmu_arctic/arctic_a0001.wav") self.signal = signal self.sampfreq = samplingrate self.world = World(samplingrate) def _callFUT(self, signal): return self.world.analyze(signal) def test_analyze(self): f0, spec, aperiod = self._callFUT(self.signal) eq_(f0.shape[0], spec.shape[0], aperiod.shape[0]) out = self.world.synthesis(f0, spec, aperiod) assert len(out) == len(self.signal), "{}, {}".format( len(out), len(self.signal)) def test_f0_estimate(self): dio_f0, dio_tx = self.world.dio(self.signal) harvest_f0, harvest_tx = self.world.harvest(self.signal) assert harvest_f0.shape[0] == dio_f0.shape[0] assert harvest_tx.shape[0] == dio_tx.shape[0] def test_sbs(self): f0, tx = self.world.estimate_f0(self.signal) spec = self.world.cheaptrick(self.signal, f0, tx) aperiod = self.world.d4c(self.signal, f0, tx) out = self.world.synthesis(f0, spec, aperiod) assert len(out) == len(self.signal), "{}, {}".format( len(out), len(self.signal))
class WorldTest(TestCase): def setUp(self): signal, samplingrate, _ = waveread("test/cmu_arctic/arctic_a0001.wav") self.signal = signal self.sampfreq = samplingrate self.world = World(samplingrate) def _callFUT(self, signal): return self.world.analyze(signal) def test_analyze(self): f0, spec, aperiod = self._callFUT(self.signal) eq_(f0.shape[0], spec.shape[0], aperiod.shape[0]) out = self.world.synthesis(f0, spec, aperiod) assert len(out) == len(self.signal), "{}, {}".format(len(out), len(self.signal))
class SynthesisTest(TestCase): def setUp(self): signal, samplingrate, _ = waveread("test/cmu_arctic/arctic_a0001.wav") self.world = World(samplingrate) self.alpha = estimate_alpha(samplingrate) self.samplingrate = samplingrate self.signal = signal self.f0, self.spec_mat, _ = self.world.analyze(signal) self.ep = ExcitePulse(16000, 80, False) self.order = 24 def test_synthesis_filter(self): excite = self.ep.gen(self.f0) mcep_mat = spec2mcep_from_matrix(self.spec_mat, self.order, self.alpha) coef_mat = [] for i in range(mcep_mat.shape[0]): coef_mat.append(mcep2coef(mcep_mat[i], 0.41)) coef_mat = np.array(coef_mat) mlsa = MLSAFilter(self.order, self.alpha, 5) syn = Synthesis(80, mlsa) synth = syn.synthesis(excite, coef_mat)
def setUp(self): signal, samplingrate, _ = waveread("test/cmu_arctic/arctic_a0001.wav") self.signal = signal self.sampfreq = samplingrate self.world = World(samplingrate)
def get_all_coefs(signal, sr): world = World(sr, float(hop_length) / sr * 1000) f0, spec_mat, aperiod_mat = world.analyze(np.float64(signal)) mcep_mat = spec2mcep_from_matrix(spec_mat, order, alpha) return f0, mcep_mat, aperiod_mat