Ejemplo n.º 1
0
func RunMultiTask(list string) {
	list_file := kaldi.TaskList(list)
	fl, err := os.Open(list_file)
	if err != nil {
		kaldi.Err().Println("Can not open task list:", list_file)
	}
	defer fl.Close()

	sc := bufio.NewScanner(fl)
	kaldi.Trace().Println("Task List File:", list_file)
	var wg sync.WaitGroup
	for sc.Scan() {
		str := sc.Text()
		kaldi.Trace().Println("Task String:", str)
		if strings.HasPrefix(str, "//") || len(str) == 0 {
			continue
		}
		wg.Add(1)
		go func(str string) {
			defer wg.Done()
			for _, field := range strings.Split(str, ";") {
				if len(strings.Trim(field, "\n ")) == 0 {
					continue
				}
				items := strings.Split(field, "#")
				RunTask(strings.Trim(items[0], " \n"), strings.Trim(items[1], " \n"))
			}
		}(str)
	}
	wg.Wait()
}
Ejemplo n.º 2
0
func main() {
	var list, scope, root, lm string
	var manual bool
	flag.StringVar(&root, "root", "", "root path")
	flag.StringVar(&lm, "lm", "", "language model")
	flag.StringVar(&list, "list", "", "task list")
	flag.StringVar(&scope, "scope", "-1", "scope: number ,1-3,4,5 ")
	flag.BoolVar(&manual, "manual", false, "manual to control servers (default=false) ")
	flag.Parse()
	kaldi.Init(root, lm)
	defer kaldi.Uninit()
	kaldi.Trace().Println("task-run")
	if !manual {
		kaldi.DevInstance().AutoSync()
		kaldi.DevInstance().SortGpu()
		kaldi.DevInstance().PrintNodes(true)
		kaldi.DevInstance().SortCpu()
		kaldi.DevInstance().PrintNodes(false)
	}

	if list != "" {
		RunMultiTask(list)
		return
	}

	if flag.NArg() < 1 {
		fmt.Println("No enough args!")
		return
	}
	tag := flag.Arg(0)
	kaldi.Trace().Println("tag", tag)
	RunTask(tag, scope)
}
Ejemplo n.º 3
0
func ParseCFGStream(reader io.Reader) []Config {
	cfg := []Config{}
	for {
		dec := json.NewDecoder(reader)
		t := NewConfig()
		err := dec.Decode(t)
		kaldi.Trace().Println("config", t)
		if err != nil {
			kaldi.Err().Println("Parsing Config Error:", err)
			break
		}
		cfg = append(cfg, *t)
	}
	kaldi.Trace().Println("configs", cfg)
	return cfg
}
Ejemplo n.º 4
0
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)
	}
}
Ejemplo n.º 5
0
func parseRange(str string) ([]int, error) {
	kaldi.Trace().Println("Scope string", str)
	res := []int{}
	subpart := strings.Split(str, ",")
	for _, part := range subpart {
		items := strings.Split(part, "~")
		boundary := make([]int, len(items), len(items))
		for idx, _ := range items {
			if len(items[idx]) == 0 {
				boundary[idx] = -1
				continue
			}
			tmp, err := strconv.ParseInt(items[idx], 10, 32)
			if err != nil {
				return []int{}, fmt.Errorf("Syntax Err: parse item to int err: ", err)
			}
			boundary[idx] = int(tmp)
		}

		if len(boundary) > 2 {
			return []int{}, fmt.Errorf("Syntax Err: range item pair disatteched ")
		}
		if len(boundary) == 1 {
			boundary = append(boundary, boundary[0])
		}
		for i := boundary[0]; i <= boundary[1]; i++ {
			res = append(res, i)
		}
	}
	return res, nil
}
Ejemplo n.º 6
0
func main() {
	var vars bool
	var feat, dy, tag string
	flag.StringVar(&feat, "feat", "mfcc", "mfcc, bnf(default)")
	flag.StringVar(&dy, "dy", "delta", "raw, delta(default) ")
	flag.StringVar(&tag, "tag", "", "anything, normal(default)")
	flag.BoolVar(&vars, "vars", false, "true, false(default)")
	flag.PrintDefaults()
	flag.Parse()

	kaldi.Init()
	defer kaldi.Uninit()
	kaldi.Trace().Println("train-dnn")

	dt := kaldi.NewDnnTask(feat)
	dt.TaskConf.Btrain = true
	dt.TaskConf.Bdecode = true
	dt.Dnn.ModelConf.Dynamic = dy
	dt.Dnn.ModelConf.Norm.Cmvn.Mean = true
	dt.Dnn.ModelConf.Norm.Cmvn.Vars = vars
	kaldi.WriteTask(dt)
	if err := dt.Run(); err != nil {
		kaldi.Err().Println()
	}

}
Ejemplo n.º 7
0
func main() {

	kaldi.Init()
	defer kaldi.Uninit()
	kaldi.Trace().Println("train-mono")
	m := kaldi.NewMonoTask()
	kaldi.WriteTask(m)
	if err := m.Run(); err != nil {
		kaldi.Err().Println()
	}
}
Ejemplo n.º 8
0
func main() {
	var feat, dy, tag string
	flag.StringVar(&feat, "feat", "mfcc", "mfcc, bnf(default)")
	flag.StringVar(&dy, "dy", "delta", "raw, delta(default) ")
	flag.StringVar(&tag, "tag", "", "anything, normal(default)")
	flag.PrintDefaults()
	flag.Parse()

	kaldi.Init()
	defer kaldi.Uninit()
	kaldi.Trace().Println("mk-align")
	a := kaldi.NewAlignTask(feat)
	a.Dynamic = dy
	for _, name := range flag.Args() {
		kaldi.Trace().Println("Make alignment of name :", name)
		a.Name = name
		kaldi.WriteTask(a)
		if err := a.Run(); err != nil {
			kaldi.Err().Println()
		}
	}
}
Ejemplo n.º 9
0
func main() {
	var manual bool
	var num int
	flag.BoolVar(&manual, "manual", false, "manual to control servers (default=false) ")
	flag.IntVar(&num, "n", 4, "number of parallel processing")
	flag.Parse()
	kaldi.Init("", "")
	defer kaldi.Uninit()
	kaldi.Trace().Println("cmd-run")

	if flag.NArg() == 0 {
		kaldi.Trace().Println("No enough args!")
		return
	}

	config := flag.Arg(0)
	kaldi.Trace().Println("The first Arg:", config)

	cfgs := ParseCFGFile(config)
	kaldi.Trace().Println(cfgs)
	ApplyCmds(cfgs, num)
}
Ejemplo n.º 10
0
func SingleTask(tag string, idx int) {
	tasks := TasksFrom(tag)
	length := len(tasks)
	if idx >= length {
		kaldi.Err().Println("Out of task range :", length)
		return
	}
	if idx >= 0 {
		kaldi.Trace().Println("Task Idx:", idx)
		tasks[idx].Run()
		return
	}
	kaldi.Trace().Printf("%d Tasks in file [%s] will be run!\n", len(tasks), tag)
	var wg sync.WaitGroup
	for i, t := range tasks {
		wg.Add(1)
		go func(idx int, t kaldi.TaskRuner) {
			defer wg.Done()
			kaldi.Trace().Println("Task Idx:", idx)
			t.Run()
		}(i, t)
	}
	wg.Wait()
}
Ejemplo n.º 11
0
func TasksFrom(identifier string) []kaldi.TaskRuner {
	file := kaldi.TaskFile(identifier)
	kaldi.Trace().Println("Selected Task:", file)
	fts, err := os.Open(file)
	if err != nil {
		kaldi.Err().Println("Can not open task:", file)
	}
	defer fts.Close()
	taskId := strings.Split(identifier, "_")[0]
	task_func := kaldi.TaskFromFunc(taskId)
	if task_func == nil {
		kaldi.Err().Println("No effective TaskFromFunc for ", taskId)
		return []kaldi.TaskRuner{}
	}
	return task_func(fts)
}
Ejemplo n.º 12
0
func RunTask(tag, scope string) error {
	idx_list, err := parseRange(scope)
	if err != nil {
		kaldi.Err().Println("Parse range:", err)
		return fmt.Errorf("Parse range:", err)
	}
	kaldi.Trace().Println("Range:", idx_list)
	var wg sync.WaitGroup
	for _, value := range idx_list {
		wg.Add(1)
		go func(tag string, idx int) {
			defer wg.Done()
			SingleTask(tag, idx)
		}(tag, value)
	}
	wg.Wait()
	return nil
}
Ejemplo n.º 13
0
func main() {
	var dy string
	var vars bool
	flag.StringVar(&dy, "dy", "raw", "raw(default),delta")
	flag.BoolVar(&vars, "vars", false, "flase(default)")
	flag.PrintDefaults()
	flag.Parse()
	kaldi.Init()
	defer kaldi.Uninit()

	kaldi.Trace().Println("mk-bnf")
	b := kaldi.NewBnfTask()
	b.ModelConf.Dynamic = dy
	b.ModelConf.Norm.Cmvn.Vars = vars
	kaldi.WriteTask(b)
	// if err := b.Run(); err != nil {
	// 	kaldi.Err().Println()
	// }

}
Ejemplo n.º 14
0
func main() {
	var name string
	flag.StringVar(&name, "name", "tri2.cmn", "tri2.cmn(default)")
	flag.PrintDefaults()
	flag.Parse()

	kaldi.Init()
	defer kaldi.Uninit()
	kaldi.Trace().Println("mk-fmllr")

	f := kaldi.NewFmllrTask()
	f.Src.Name = name
	f.Src.Exp = "GMM"

	kaldi.WriteTask(f)
	if err := f.Run(); err != nil {
		kaldi.Err().Println()
	}

}
Ejemplo n.º 15
0
func main() {
	var vars bool
	var feat, dy string
	flag.StringVar(&feat, "feat", "mfcc", "mfcc, bnf(default)")
	flag.StringVar(&dy, "dy", "delta", "raw, delta(default) ")
	flag.BoolVar(&vars, "vars", false, "true, false(default)")
	flag.PrintDefaults()
	flag.Parse()

	kaldi.Init()
	defer kaldi.Uninit()
	kaldi.Trace().Println("train-gmm")
	g := kaldi.NewGmmTask(feat)
	g.ModelConf.Dynamic = dy
	g.ModelConf.Norm.Cmvn.Mean = true
	g.ModelConf.Norm.Cmvn.Vars = vars
	kaldi.WriteTask(g)
	if err := g.Run(); err != nil {
		kaldi.Err().Println()
	}
}
Ejemplo n.º 16
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)
			}
		}
	}
}
Ejemplo n.º 17
0
func main() {
	var tag string
	flag.StringVar(&tag, "tag", "normal", "normal(default)")
	flag.PrintDefaults()
	flag.Parse()
	kaldi.Init()
	defer kaldi.Uninit()
	kaldi.Trace().Println("mk-cmvn")
	if flag.NArg() < 1 {
		kaldi.Err().Println("no enough args for feature type")
	}

	for _, feat := range flag.Args() {
		c := kaldi.NewCmvnTask()
		c.Feat = feat
		kaldi.WriteTask(c)
		if err := c.Run(); err != nil {
			kaldi.Err().Println()
		}
	}

}