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
17// Package speech is an auto-generated package for the
18// Cloud Speech-to-Text API.
19//
20// Converts audio to text by applying powerful neural network models.
21//
22// Example usage
23//
24// To get started with this package, create a client.
25//  ctx := context.Background()
26//  c, err := speech.NewClient(ctx)
27//  if err != nil {
28//  	// TODO: Handle error.
29//  }
30//  defer c.Close()
31//
32// The client will use your default application credentials. Clients should be reused instead of created as needed.
33// The methods of Client are safe for concurrent use by multiple goroutines.
34// The returned client must be Closed when it is done being used.
35//
36// Using the Client
37//
38// The following is an example of making an API call with the newly created client.
39//
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//  	// See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/speech/v1#RecognizeRequest.
50//  }
51//  resp, err := c.Recognize(ctx, req)
52//  if err != nil {
53//  	// TODO: Handle error.
54//  }
55//  // TODO: Use resp.
56//  _ = resp
57//
58// Use of Context
59//
60// The ctx passed to NewClient is used for authentication requests and
61// for creating the underlying connection, but is not used for subsequent calls.
62// Individual methods on the client use the ctx given to them.
63//
64// To close the open connection, use the Close() method.
65//
66// For information about setting deadlines, reusing contexts, and more
67// please visit https://pkg.go.dev/cloud.google.com/go.
68package speech // import "cloud.google.com/go/speech/apiv1"
69
70import (
71	"context"
72	"os"
73	"runtime"
74	"strconv"
75	"strings"
76	"unicode"
77
78	"google.golang.org/api/option"
79	"google.golang.org/grpc/metadata"
80)
81
82// For more information on implementing a client constructor hook, see
83// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
84type clientHookParams struct{}
85type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)
86
87const versionClient = "20210921"
88
89func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
90	out, _ := metadata.FromOutgoingContext(ctx)
91	out = out.Copy()
92	for _, md := range mds {
93		for k, v := range md {
94			out[k] = append(out[k], v...)
95		}
96	}
97	return metadata.NewOutgoingContext(ctx, out)
98}
99
100func checkDisableDeadlines() (bool, error) {
101	raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE")
102	if !ok {
103		return false, nil
104	}
105
106	b, err := strconv.ParseBool(raw)
107	return b, err
108}
109
110// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
111func DefaultAuthScopes() []string {
112	return []string{
113		"https://www.googleapis.com/auth/cloud-platform",
114	}
115}
116
117// versionGo returns the Go runtime version. The returned string
118// has no whitespace, suitable for reporting in header.
119func versionGo() string {
120	const develPrefix = "devel +"
121
122	s := runtime.Version()
123	if strings.HasPrefix(s, develPrefix) {
124		s = s[len(develPrefix):]
125		if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 {
126			s = s[:p]
127		}
128		return s
129	}
130
131	notSemverRune := func(r rune) bool {
132		return !strings.ContainsRune("0123456789.", r)
133	}
134
135	if strings.HasPrefix(s, "go1") {
136		s = s[2:]
137		var prerelease string
138		if p := strings.IndexFunc(s, notSemverRune); p >= 0 {
139			s, prerelease = s[:p], s[p:]
140		}
141		if strings.HasSuffix(s, ".") {
142			s += "0"
143		} else if strings.Count(s, ".") < 2 {
144			s += ".0"
145		}
146		if prerelease != "" {
147			s += "-" + prerelease
148		}
149		return s
150	}
151	return "UNKNOWN"
152}
153