forked from xinyunh0929/golang-samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
captionasync_test.go
64 lines (54 loc) · 1.51 KB
/
captionasync_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
56
57
58
59
60
61
62
63
64
// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"testing"
"golang.org/x/net/context"
speech "cloud.google.com/go/speech/apiv1"
"github.com/GoogleCloudPlatform/golang-samples/internal/testutil"
)
func TestRecognize(t *testing.T) {
testutil.SystemTest(t)
ctx := context.Background()
client, err := speech.NewClient(ctx)
if err != nil {
t.Fatal(err)
}
resp, err := send(client, "../testdata/quit.raw")
if err != nil {
t.Fatal(err)
}
if len(resp.Results) == 0 {
t.Fatal("got no results; want at least one")
}
result := resp.Results[0]
if len(result.Alternatives) < 1 {
t.Fatal("got no alternatives; want at least one")
}
if got, want := result.Alternatives[0].Transcript, "quit"; got != want {
t.Errorf("Transcript: got %q; want %q", got, want)
}
}
func TestRecognizeGCS(t *testing.T) {
testutil.SystemTest(t)
ctx := context.Background()
client, err := speech.NewClient(ctx)
if err != nil {
t.Fatal(err)
}
resp, err := sendGCS(client, "gs://python-docs-samples-tests/speech/audio.raw")
if err != nil {
t.Fatal(err)
}
if len(resp.Results) == 0 {
t.Fatal("got no results; want at least one")
}
result := resp.Results[0]
if len(result.Alternatives) < 1 {
t.Fatal("got no alternatives; want at least one")
}
if got, want := result.Alternatives[0].Transcript, "how old is the Brooklyn Bridge"; got != want {
t.Errorf("Transcript: got %q; want %q", got, want)
}
}