Exemplo n.º 1
0
func main() {
	if len(os.Args) != 3 {
		fmt.Fprintln(os.Stderr, "Usage: classify <rnn> <sample.wav>")
		os.Exit(1)
	}

	rnnData, err := ioutil.ReadFile(os.Args[1])
	if err != nil {
		die(err)
	}
	seqFunc, err := rnn.DeserializeBidirectional(rnnData)
	if err != nil {
		die(err)
	}
	sample, err := cubewhisper.ReadAudioFile(os.Args[2])
	if err != nil {
		die(err)
	}

	inSeq := make([]autofunc.Result, len(sample))
	for i, x := range sample {
		inSeq[i] = &autofunc.Variable{Vector: x}
	}
	res := seqFunc.BatchSeqs([][]autofunc.Result{inSeq})

	classification := ctc.PrefixSearch(res.OutputSeqs()[0], PrefixThreshold)
	labels := make([]cubewhisper.Label, len(classification))
	for i, c := range classification {
		labels[i] = cubewhisper.Label(c)
	}
	fmt.Println("Raw labels:", labels)
	fmt.Println("Algorithm:", cubewhisper.LabelsToMoveString(labels))
}
Exemplo n.º 2
0
func ReadSamples(dir string) (sgd.SampleSet, error) {
	index, err := speechdata.LoadIndex(dir)
	if err != nil {
		return nil, err
	}

	var samples sgd.SliceSampleSet
	for _, sample := range index.Samples {
		if sample.File == "" {
			continue
		}
		label := cubewhisper.LabelsForMoveString(sample.Label)
		wavPath := filepath.Join(index.DirPath, sample.File)
		sampleSeq, err := cubewhisper.ReadAudioFile(wavPath)
		if err != nil {
			return nil, err
		}
		intLabel := make([]int, len(label))
		for i, x := range label {
			intLabel[i] = int(x)
		}
		samples = append(samples, ctc.Sample{Input: sampleSeq, Label: intLabel})
	}

	return samples, nil
}
Exemplo n.º 3
0
func main() {
	if len(os.Args) != 3 {
		fmt.Fprintln(os.Stderr, "Usage: rate <rnn> <sample dir>")
		os.Exit(1)
	}

	rnnData, err := ioutil.ReadFile(os.Args[1])
	if err != nil {
		die("Read RNN", err)
	}
	seqFunc, err := rnn.DeserializeBidirectional(rnnData)
	if err != nil {
		die("Deserialize RNN", err)
	}

	index, err := speechdata.LoadIndex(os.Args[2])
	if err != nil {
		die("Load speech index", err)
	}

	log.Println("Crunching numbers...")

	var res results
	for _, sample := range index.Samples {
		if sample.File == "" {
			continue
		}
		label := cubewhisper.LabelsForMoveString(sample.Label)
		wavPath := filepath.Join(index.DirPath, sample.File)
		sampleSeq, err := cubewhisper.ReadAudioFile(wavPath)
		if err != nil {
			die("Load sample audio", err)
		}
		intLabel := make([]int, len(label))
		for i, x := range label {
			intLabel[i] = int(x)
		}
		output := evalSample(seqFunc, sampleSeq)
		likelihood := ctc.LogLikelihood(output, intLabel).Output()[0]
		res.Likelihoods = append(res.Likelihoods, likelihood)
		res.SampleIDs = append(res.SampleIDs, sample.ID)
	}
	sort.Sort(&res)

	for i, id := range res.SampleIDs {
		likelihood := res.Likelihoods[i]
		fmt.Printf("%d. %s - %e\n", i, id, likelihood)
	}
}