Spaces:
Sleeping
Sleeping
package main | |
import ( | |
"flag" | |
"vad_go/dsp/audio" | |
"vad_go/dsp/streaming_vad" | |
"fmt" | |
) | |
func main () { | |
args := flag.String("filename", "", "input wav audio file") | |
flag.Parse() | |
var filename string = *args | |
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, 0.4, 3.0) | |
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) | |
} | |
} | |