func TestMGLSASynthesis(t *testing.T) {
	var (
		testData   []float64
		frameShift = 80
		frameLen   = 512
		alpha      = 0.41
		stage      = 12
		gamma      = -1.0 / float64(stage)
		order      = 24
		f0Seq      []float64
		ex         []float64
		mgc        [][]float64
	)

	w, err := io.ReadWav("../test_files/test16k.wav")
	if err != nil {
		log.Fatal(err)
	}
	testData = w.GetMonoData()

	// F0
	f0Seq = f0.SWIPE(testData, 16000, frameShift, 60.0, 700.0)

	// MGCep
	frames := gossp.DivideFrames(testData, frameLen, frameShift)
	mgc = make([][]float64, len(frames))
	for i, frame := range frames {
		mgc[i] = mgcep.MGCep(window.BlackmanNormalized(frame),
			order, alpha, gamma)
	}

	// adjast number of frames
	m := min(len(f0Seq), len(mgc))
	f0Seq, mgc = f0Seq[:m], mgc[:m]

	// Excitation
	g := &excite.PulseExcite{
		SampleRate: 16000,
		FrameShift: frameShift,
	}
	ex = g.Generate(f0Seq)

	// Waveform generation
	synth := NewMGLSASpeechSynthesizer(order, alpha, stage, frameShift)

	_ = synth.Synthesis(ex, mgc)
	// TODO(ryuichi) valid check
}
示例#2
0
func TestMGLSAConsistencyWithSPTK(t *testing.T) {
	var (
		testData []float64
		order    = 25
		alpha    = 0.41
		stage    = 12
		gamma    = -1.0 / float64(stage)
	)

	file, err := os.Open("../test_files/test16k.wav")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	w, werr := wav.ReadWav(file)
	if werr != nil {
		log.Fatal(werr)
	}
	testData = w.GetMonoData()

	data := testData[:512]

	mgc := mgcep.MGCep(window.BlackmanNormalized(data), order, alpha, gamma)
	filterCoef := MGCep2MGLSAFilterCoef(mgc, alpha, gamma)

	mf := NewMGLSAFilter(order, alpha, stage)

	// tricky allocation based on the SPTK (just for test)
	d := make([]float64, (order+1)*stage)

	tolerance := 1.0e-64

	for _, val := range data {
		y1 := mf.Filter(val, filterCoef)
		y2 := sptk.MGLSADF(val, filterCoef, order, alpha, stage, d)
		err := math.Abs(y1 - y2)
		if err > tolerance {
			t.Errorf("Error: %f, want less than %f.", err, tolerance)
		}
	}

}