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 }
func main() { var manual bool var gpu bool flag.BoolVar(&manual, "manual", false, "manual to control servers (default=false) ") flag.BoolVar(&gpu, "g", false, "gpu dependenc") flag.Parse() kaldi.Init("", "") defer kaldi.Uninit() if flag.NArg() == 0 { kaldi.Trace().Println("No enough args!") return } cmd := strings.Join(flag.Args(), " ") var err error if manual { err = kaldi.BashRun(cmd) } else { if gpu { err = kaldi.GpuBashRun(cmd) } else { err = kaldi.CpuBashRun(cmd) } } if err != nil { kaldi.Err().Println("Cmd Err:", cmd, "\t", err) os.Exit(1) } }
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) }
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 }
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) } }