package main import ( "flag" "vad_go/dsp/audio" "vad_go/dsp/streaming_vad" "fmt" ) func main () { filenamePtr := flag.String("filename", "", "input wav audio file") silenceTimePtr := flag.Float64("silence_time", 0.0, "silence time in seconds") longestActivatePtr := flag.Float64("longest_activate", 0.0, "longest activate time in seconds") flag.Parse() var filename string = *filenamePtr var silenceTime float32 = float32(*silenceTimePtr) var longestActivate float32 = float32(*longestActivatePtr) fmt.Println(filename) var wavInfo audio.WavInfoType err := wavInfo.ParseFromFile(filename) if err != nil { fmt.Println("wavInfo.ParseFromFile failed.") } fmt.Printf("sample rate: %d\n", wavInfo.Fmt.SampleRate) float32Samples := wavInfo.GetFloat32Samples(0, 2) var int16Samples []int16 var size uint32 var point int16 for i := 0; i < len(wavInfo.Data.Sample); i++ { point = int16(float32Samples[i] * (1 << 15)) + 1 int16Samples = append(int16Samples, point) } size = uint32(len(int16Samples)) fmt.Printf("sample number: %d\n", size) winSize := uint32(7000) winStep := uint32(7000) count := uint32(0) sv := streaming_vad.StreamingVadType{} sv.Init(8000, silenceTime, longestActivate) var begin uint32 var end uint32 //var bufferSize uint32 for true { begin = count * winStep end = begin + winSize //fmt.Println(end) if begin >= size { break } if end >= size { end = size } buffer := int16Samples[begin:end] //fmt.Printf("bufferSize: %d\n", bufferSize) //fmt.Printf("buffer: %d\n", buffer) count++ err = sv.ProcessSpeechByChunk(buffer) if err != nil { fmt.Println(err) break } //if count > 3 { // break //} } fmt.Println(len(sv.VadEventMarkerDeque)) var marker streaming_vad.VadEventMarkerType for i := 0; i < len(sv.VadEventMarkerDeque); i++ { marker = sv.VadEventMarkerDeque[i] fmt.Println(marker.Time) fmt.Println(marker.VadFlag) } }