/
recognize.go
42 lines (34 loc) · 896 Bytes
/
recognize.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
package stt
import (
"time"
"github.com/xavidop/dialogflow-cx-test-runner/internal/global"
)
func Recognize(input string, locale string) error {
client, err := CreateSTTClient()
if err != nil {
return err
}
defer client.Close()
resp, err := ExecuteRecognition(client, input, locale)
if err != nil {
return err
}
if global.Output == "json" {
global.Log.Infof("%v\n", resp.GetResults())
} else {
for _, resp := range resp.GetResults() {
if global.Verbose {
global.Log.Infof("Duration time: %d miliseconds\n", resp.GetResultEndTime().GetNanos()/int32(time.Millisecond))
}
i := 1
for _, alternative := range resp.GetAlternatives() {
global.Log.Infof("%d. Detected: %s\n", i, alternative.GetTranscript())
if global.Verbose {
global.Log.Infof("%d. Confidence: %f%% \n", i, alternative.GetConfidence()*100)
}
i++
}
}
}
return nil
}