Example #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)
}
Example #2
0
func main() {
	fmt.Println("update-feats-scp")
	var data string
	flag.StringVar(&data, "data", "", "data dir")
	flag.Parse()
	param := flag.Arg(0)
	fmt.Println("param", param)
	if !kaldi.DirExist(param) {
		fmt.Println("No exist param dir:", param)
		return
	}
	Clear(param)
	filepath.Walk(param, DirCheck)
	if data != "" {
		ConstructData(data, param)
	}
}
Example #3
0
func deal_const(src, dst string) {
	file := file_files(dst, "*")
	if len(file) < 1 {
		fmt.Println("No scp files, maybe something wrong!")
	}

	for _, f := range file {

		name := path.Base(f)
		parts := strings.Split(name, ".")
		dir := path.Join(path.Dir(f), strings.Join(parts[:len(parts)-1], "."))
		if kaldi.DirExist(dir) {
			f_src := path.Join(src, path.Base(dir), parts[len(parts)-1])
			os.Rename(f_src, path.Join(dir, parts[len(parts)-1]))
		}
	}

}
Example #4
0
func main() {
	fmt.Println("mk-mfcc")
	flag.Parse()
	if flag.NArg() < 2 {
		log.Println("No enough args!")
		return
	}
	src := flag.Arg(0)
	dst := flag.Arg(1)
	fmt.Println(src, dst)
	if !kaldi.DirExist(src) {
		log.Println("no exist source dir :", src)
		return
	}

	var wg sync.WaitGroup
	filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
		if !info.IsDir() {
			return nil
		}
		wg.Add(1)
		go func(dir string) {
			defer wg.Done()
			files, err := filepath.Glob(dir + "/*.wav")
			if err != nil {
				log.Println(err)
				return
			}
			if len(files) == 0 {
				return
			}
			rel, rerr := filepath.Rel(src, dir)
			if rerr != nil {
				log.Println(err)
				return
			}
			dst_dir := filepath.Join(dst, rel)
			MakeMfcc(files, dst_dir)
		}(path)
		return nil
	})
	wg.Wait()
}