Spaces:
Sleeping
Sleeping
File size: 1,963 Bytes
382cf0c 512e9e2 382cf0c 45612e0 7f82739 382cf0c 45612e0 01a9723 382cf0c 45612e0 382cf0c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
package main
import (
"flag"
"nx_vad/dsp/audio"
"nx_vad/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)
}
}
|