Beispiel #1
0
func main() {

	var src, ext, reg string
	flag.StringVar(&src, "src", "./", "Source directory of the corpus")
	flag.StringVar(&ext, "ext", "wav", "extension  of the corpus with default (wav)")
	flag.StringVar(&reg, "reg", "", "regular expression for searching files)")
	flag.Parse()
	fmt.Printf("src:%s\next:%s\nreg:%s\n", src, ext, reg)
	if !kaldi.DirExist(src) {
		fmt.Printf("Error: No Exist src directory: %s\n", src)
		return
	}
	pattern := "*" + reg + "*." + ext

	file_cmd := kaldi.JoinArgs(
		"find",
		src+"/",
		"-type f ",
		"-iname "+pattern)
	fmt.Println("Find: ", file_cmd)
	output, _ := kaldi.BashOutput(file_cmd)
	files := strings.Split(string(output[:]), "\n")
	total_len := 0.0
	count := 0
	for _, file := range files {
		cmd := kaldi.JoinArgs(
			"sox",
			strings.Trim(file, "\n "),
			"-n stat",
			"2>&1",
			"|awk '/Length/ {print $3}'")
		output, err := kaldi.BashOutput(cmd)
		if err != nil {
			fmt.Println("Missed file:", file)
			continue
		}
		length, err := strconv.ParseFloat(strings.Trim(string(output[:]), "\n \t"), 64)
		if err != nil {
			fmt.Println("Missed file:", file)
			continue
		}
		count++
		total_len += length
	}

	fmt.Println("Total Count: ", len(files))
	fmt.Println("Total Len(hours): ", total_len/3600)
	fmt.Println("Wave Count: ", count)
	fmt.Println("Missed Count: ", len(files)-count)
}
Beispiel #2
0
func MakeMfcc(files []string, dst string) error {
	dir, _ := filepath.Abs(dst)
	kaldi.InsureDir(dir)
	log := filepath.Join(dir, "log")
	kaldi.InsureDir(log)
	kaldi.BashRun("rm " + dir + "/*.*")
	jobs := make(chan string, 100)
	var wg sync.WaitGroup

	for i := 0; i < 10; i++ {
		wg.Add(1)
		go func(id int, job <-chan string) {
			defer wg.Done()
			for f := range jobs {
				wav, _ := filepath.Abs(f)
				cmd := kaldi.JoinArgs("cd ~/rev_kaldi; ./steps/make_mfcc.sh",
					"--nj 8", wav, log, dir)
				fmt.Println(cmd)
				kaldi.BashRun(cmd)
			}
		}(i, jobs)
	}
	for _, f := range files {
		jobs <- f
	}
	close(jobs)
	wg.Wait()

	return nil
}
Beispiel #3
0
func ConstructData(data, param string) {
	cmd := kaldi.JoinArgs(
		"find", param, "-type f", "-iname \"feats.scp\"")
	output, _ := kaldi.BashOutput(cmd)
	files := strings.Split(strings.Trim(string(output), " \n"), "\n")
	if len(files) == 0 {
		return
	}
	for _, f := range files {
		dst := strings.Replace(f, "param/", "data/", 1)
		kaldi.InsureDir(path.Dir(dst))
		cmd := kaldi.JoinArgs("cp", f, dst)
		fmt.Println(cmd)
		kaldi.BashRun(cmd)
	}
}
Beispiel #4
0
func MergeScp(dir string) error {
	file := path.Join(dir, "feats.scp")
	os.Rename(file, file+".bakup")
	cmd := kaldi.JoinArgs(
		"cat", path.Join(dir, "*.scp"),
		"|sort",
		"> ", file)
	return kaldi.BashRun(cmd)
}
Beispiel #5
0
func Clear(param string) error {
	keys := []string{"*cmvn*", "feats.scp*"}
	for _, key := range keys {
		cmd := kaldi.JoinArgs(
			"find", param, "-type f", "-iname", "\""+key+"\"",
			"|xargs rm")
		fmt.Println(cmd)
		err := kaldi.BashRun(cmd)
		if err != nil {
			fmt.Println(err)
		}
	}
	return nil
}
Beispiel #6
0
func SyncPs(svr string) []ProcInfo {
	procs := []ProcInfo{}
	cmd_str := kaldi.JoinArgs("ssh",
		svr,
		"\"ps -u ren -o comm\"")
	out, err := kaldi.BashOutput(cmd_str)
	if err != nil {
		// log.Println("Err:", err)
	} else {
		str := strings.Trim(string(out), "\n ")
		ps := strings.Split(str, "\n")
		for _, v := range ps {
			procs = append(procs, ProcInfo{svr, v, 1})
		}
	}
	return procs
}
Beispiel #7
0
func ApplyCmd(c Config) {
	file, err := os.Open(c.List)
	kaldi.Trace().Println("list :", c.List)
	if err != nil {
		kaldi.Err().Println("Open list file :", err)
		return
	}
	defer file.Close()

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		item := strings.Trim(scanner.Text(), " \n")
		if len(item) != 0 {
			cmd := kaldi.JoinArgs(c.Cmd, c.Args, item)
			err := kaldi.CpuBashRun(cmd)
			if err != nil {
				kaldi.Err().Println("Cmd Err:", cmd, "\t", err)
			}
		}
	}
}