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//   NOTE: This package is in beta. It is not stable, and may be subject to changes.
23//
24// Use of Context
25//
26// The ctx passed to NewClient is used for authentication requests and
27// for creating the underlying connection, but is not used for subsequent calls.
28// Individual methods on the client use the ctx given to them.
29//
30// To close the open connection, use the Close() method.
31//
32// For information about setting deadlines, reusing contexts, and more
33// please visit https://pkg.go.dev/cloud.google.com/go.
34package speech // import "cloud.google.com/go/speech/apiv1p1beta1"
35
36import (
37	"context"
38	"os"
39	"runtime"
40	"strconv"
41	"strings"
42	"unicode"
43
44	"google.golang.org/api/option"
45	"google.golang.org/grpc/metadata"
46)
47
48// For more information on implementing a client constructor hook, see
49// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors.
50type clientHookParams struct{}
51type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error)
52
53const versionClient = "20210624"
54
55func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context {
56	out, _ := metadata.FromOutgoingContext(ctx)
57	out = out.Copy()
58	for _, md := range mds {
59		for k, v := range md {
60			out[k] = append(out[k], v...)
61		}
62	}
63	return metadata.NewOutgoingContext(ctx, out)
64}
65
66func checkDisableDeadlines() (bool, error) {
67	raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE")
68	if !ok {
69		return false, nil
70	}
71
72	b, err := strconv.ParseBool(raw)
73	return b, err
74}
75
76// DefaultAuthScopes reports the default set of authentication scopes to use with this package.
77func DefaultAuthScopes() []string {
78	return []string{
79		"https://www.googleapis.com/auth/cloud-platform",
80	}
81}
82
83// versionGo returns the Go runtime version. The returned string
84// has no whitespace, suitable for reporting in header.
85func versionGo() string {
86	const develPrefix = "devel +"
87
88	s := runtime.Version()
89	if strings.HasPrefix(s, develPrefix) {
90		s = s[len(develPrefix):]
91		if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 {
92			s = s[:p]
93		}
94		return s
95	}
96
97	notSemverRune := func(r rune) bool {
98		return !strings.ContainsRune("0123456789.", r)
99	}
100
101	if strings.HasPrefix(s, "go1") {
102		s = s[2:]
103		var prerelease string
104		if p := strings.IndexFunc(s, notSemverRune); p >= 0 {
105			s, prerelease = s[:p], s[p:]
106		}
107		if strings.HasSuffix(s, ".") {
108			s += "0"
109		} else if strings.Count(s, ".") < 2 {
110			s += ".0"
111		}
112		if prerelease != "" {
113			s += "-" + prerelease
114		}
115		return s
116	}
117	return "UNKNOWN"
118}
119