示例#1
0
func main() {
	ifilename := flag.String("i", "input.wav", "Input filename")
	flag.Parse()

	file, err := os.Open(*ifilename)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	// Read wav data
	w, werr := wav.ReadWav(file)
	if werr != nil {
		log.Fatal(werr)
	}

	input := w.GetMonoData()
	sampleRate := int(w.SampleRate)

	// Synthesis
	outfile := strings.Replace(*ifilename, ".wav", "_synthesized.wav", -1)
	start := time.Now()
	synthesized := worldExample(input, sampleRate)
	fmt.Println("Elapsed time in re-synthesis:", time.Now().Sub(start))

	// Write to file
	werr = wav.WriteMono(outfile, synthesized, w.SampleRate)
	if werr != nil {
		log.Fatal(werr)
	}
	fmt.Println(outfile, "is created.")
}
示例#2
0
文件: wav.go 项目: adityanatraj/gossp
func ReadWav(filename string) (*wav.Wav, error) {
	file, err := os.Open(filename)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	w, werr := wav.ReadWav(file)
	if werr != nil {
		return nil, werr
	}

	return w, nil
}
示例#3
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)
		}
	}

}