1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17package speech_test
18
19import (
20	"context"
21	"io"
22
23	speech "cloud.google.com/go/speech/apiv1"
24	speechpb "google.golang.org/genproto/googleapis/cloud/speech/v1"
25)
26
27func ExampleNewClient() {
28	ctx := context.Background()
29	c, err := speech.NewClient(ctx)
30	if err != nil {
31		// TODO: Handle error.
32	}
33	defer c.Close()
34
35	// TODO: Use client.
36	_ = c
37}
38
39func ExampleClient_Recognize() {
40	ctx := context.Background()
41	c, err := speech.NewClient(ctx)
42	if err != nil {
43		// TODO: Handle error.
44	}
45	defer c.Close()
46
47	req := &speechpb.RecognizeRequest{
48		// TODO: Fill request struct fields.
49	}
50	resp, err := c.Recognize(ctx, req)
51	if err != nil {
52		// TODO: Handle error.
53	}
54	// TODO: Use resp.
55	_ = resp
56}
57
58func ExampleClient_LongRunningRecognize() {
59	ctx := context.Background()
60	c, err := speech.NewClient(ctx)
61	if err != nil {
62		// TODO: Handle error.
63	}
64	defer c.Close()
65
66	req := &speechpb.LongRunningRecognizeRequest{
67		// TODO: Fill request struct fields.
68	}
69	op, err := c.LongRunningRecognize(ctx, req)
70	if err != nil {
71		// TODO: Handle error.
72	}
73
74	resp, err := op.Wait(ctx)
75	if err != nil {
76		// TODO: Handle error.
77	}
78	// TODO: Use resp.
79	_ = resp
80}
81
82func ExampleClient_StreamingRecognize() {
83	ctx := context.Background()
84	c, err := speech.NewClient(ctx)
85	if err != nil {
86		// TODO: Handle error.
87	}
88	defer c.Close()
89	stream, err := c.StreamingRecognize(ctx)
90	if err != nil {
91		// TODO: Handle error.
92	}
93	go func() {
94		reqs := []*speechpb.StreamingRecognizeRequest{
95			// TODO: Create requests.
96		}
97		for _, req := range reqs {
98			if err := stream.Send(req); err != nil {
99				// TODO: Handle error.
100			}
101		}
102		stream.CloseSend()
103	}()
104	for {
105		resp, err := stream.Recv()
106		if err == io.EOF {
107			break
108		}
109		if err != nil {
110			// TODO: handle error.
111		}
112		// TODO: Use resp.
113		_ = resp
114	}
115}
116