示例#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))
}
示例#2
0
func classifySamples() {
	emitLoading("Processing audio")

	sample := cubewhisper.SeqForAudioSamples(Samples, SampleRate)

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

	emitLoading("Running neural network")

	res := Network.BatchSeqs([][]autofunc.Result{inSeq})

	classification := ctc.PrefixSearch(res.OutputSeqs()[0], SearchBlankCutoff)
	labels := make([]cubewhisper.Label, len(classification))
	for i, c := range classification {
		labels[i] = cubewhisper.Label(c)
	}

	emitMoves(cubewhisper.LabelsToMoveString(labels), fmt.Sprintf("%v", labels))
}