Exemplo n.º 1
0
func TestMLSASynthesis(t *testing.T) {
	var (
		testData   []float64
		frameShift = 80
		frameLen   = 512
		alpha      = 0.41
		order      = 24
		pd         = 5
		f0Seq      []float64
		ex         []float64
		mc         [][]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)

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

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

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

	// Waveform generation
	synth := NewMLSASpeechSynthesizer(order, alpha, pd, frameShift)

	_ = synth.Synthesis(ex, mc)
	// TODO(ryuichi) valid check
}
Exemplo n.º 2
0
func TestMLSAConsistencyWithSPTK(t *testing.T) {
	var (
		testData []float64
		order    = 24
		alpha    = 0.41
		pd       = 5
	)

	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]

	mc := mgcep.MCep(window.BlackmanNormalized(data), order, alpha)
	filterCoef := MCep2MLSAFilterCoef(mc, alpha)

	mf := NewMLSAFilter(order, alpha, pd)

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

	tolerance := 1.0e-10

	for _, val := range data {
		y1 := mf.Filter(val, filterCoef)
		y2 := sptk.MLSADF(val, filterCoef, order, alpha, pd, d)
		err := math.Abs(y1 - y2)
		if err > tolerance {
			t.Errorf("Error: %f, want less than %f.", err, tolerance)
		}
	}
}
Exemplo n.º 3
0
func TestMC2B(t *testing.T) {
	var (
		sampleRate = 10000
		freq       = 100.0
		bufferSize = 512
		order      = 25
		alpha      = 0.35
	)
	dummyInput := createSin(freq, sampleRate, bufferSize)
	mc := mgcep.MCep(dummyInput, order, alpha)

	b1 := MC2B(mc, alpha)
	b2 := sptk.MC2B(mc, alpha)

	tolerance := 1.0e-64

	for i := range b1 {
		err := math.Abs(b1[i] - b2[i])
		if err > tolerance {
			t.Errorf("Error %f, want less than %f.", err, tolerance)
		}
	}

}
Exemplo n.º 4
0
func TestB2MCConsistencyWithSPTK(t *testing.T) {
	var (
		sampleRate = 10000
		freq       = 100.0
		bufferSize = 512
		order      = 25
		alpha      = 0.35
	)
	dummyInput := createSin(freq, sampleRate, bufferSize)
	c := mgcep.MCep(dummyInput, order, alpha)
	b := sptk.MC2B(c, alpha)

	tolerance := 1.0e-64

	mc1 := B2MC(b, alpha)
	mc2 := sptk.B2MC(b, alpha)

	for i := range mc1 {
		err := math.Abs(mc1[i] - mc2[i])
		if err > tolerance {
			t.Errorf("Error %f, want less than %f.", err, tolerance)
		}
	}
}