-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsnowboy_test.go
55 lines (44 loc) · 1.18 KB
/
snowboy_test.go
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
package snowboy
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
)
const (
resourceFile = "build/common.res"
alexaKeywordFile = "build/alexa/alexa_02092017.umdl"
)
func TestNewDetector(t *testing.T) {
d := NewDetector(resourceFile)
defer d.Close()
assert.Equal(t, resourceFile, d.ResourceFile, "NewDetect sets ResourceFile")
assert.Equal(t, float32(1.0), d.AudioGain, "Gain should default to 1.0")
}
func TestDetector_AudioFormat(t *testing.T) {
d := NewDetector(resourceFile)
defer d.Close()
d.Handle(NewDefaultHotword(alexaKeywordFile), nil)
a, b, c := d.AudioFormat()
assert.Equal(t, 16000, a)
assert.Equal(t, 1, b)
assert.Equal(t, 16, c)
}
func TestDetector_HandleSilenceFunc(t *testing.T) {
d := NewDetector(resourceFile)
defer d.Close()
// Not under test but underlying lib requires a keyword
d.Handle(NewDefaultHotword(alexaKeywordFile), nil)
handled := false
d.HandleSilenceFunc(1*time.Second, func(keyword string) {
handled = true
})
silence, err := os.Open("audio/silence.wav")
if err != nil {
t.Error("can't open silence wav")
}
d.ReadAndDetect(silence)
if !handled {
t.Error("handler in HandleSilenceFunc never called")
}
}