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 mediatranslation 18 19import ( 20 "context" 21 "math" 22 23 gax "github.com/googleapis/gax-go/v2" 24 "google.golang.org/api/option" 25 "google.golang.org/api/option/internaloption" 26 gtransport "google.golang.org/api/transport/grpc" 27 mediatranslationpb "google.golang.org/genproto/googleapis/cloud/mediatranslation/v1beta1" 28 "google.golang.org/grpc" 29 "google.golang.org/grpc/metadata" 30) 31 32var newSpeechTranslationClientHook clientHook 33 34// SpeechTranslationCallOptions contains the retry settings for each method of SpeechTranslationClient. 35type SpeechTranslationCallOptions struct { 36 StreamingTranslateSpeech []gax.CallOption 37} 38 39func defaultSpeechTranslationGRPCClientOptions() []option.ClientOption { 40 return []option.ClientOption{ 41 internaloption.WithDefaultEndpoint("mediatranslation.googleapis.com:443"), 42 internaloption.WithDefaultMTLSEndpoint("mediatranslation.mtls.googleapis.com:443"), 43 internaloption.WithDefaultAudience("https://mediatranslation.googleapis.com/"), 44 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 45 internaloption.EnableJwtWithScope(), 46 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 47 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 48 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 49 } 50} 51 52func defaultSpeechTranslationCallOptions() *SpeechTranslationCallOptions { 53 return &SpeechTranslationCallOptions{ 54 StreamingTranslateSpeech: []gax.CallOption{}, 55 } 56} 57 58// internalSpeechTranslationClient is an interface that defines the methods availaible from Media Translation API. 59type internalSpeechTranslationClient interface { 60 Close() error 61 setGoogleClientInfo(...string) 62 Connection() *grpc.ClientConn 63 StreamingTranslateSpeech(context.Context, ...gax.CallOption) (mediatranslationpb.SpeechTranslationService_StreamingTranslateSpeechClient, error) 64} 65 66// SpeechTranslationClient is a client for interacting with Media Translation API. 67// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 68// 69// Provides translation from/to media types. 70type SpeechTranslationClient struct { 71 // The internal transport-dependent client. 72 internalClient internalSpeechTranslationClient 73 74 // The call options for this service. 75 CallOptions *SpeechTranslationCallOptions 76} 77 78// Wrapper methods routed to the internal client. 79 80// Close closes the connection to the API service. The user should invoke this when 81// the client is no longer required. 82func (c *SpeechTranslationClient) Close() error { 83 return c.internalClient.Close() 84} 85 86// setGoogleClientInfo sets the name and version of the application in 87// the `x-goog-api-client` header passed on each request. Intended for 88// use by Google-written clients. 89func (c *SpeechTranslationClient) setGoogleClientInfo(keyval ...string) { 90 c.internalClient.setGoogleClientInfo(keyval...) 91} 92 93// Connection returns a connection to the API service. 94// 95// Deprecated. 96func (c *SpeechTranslationClient) Connection() *grpc.ClientConn { 97 return c.internalClient.Connection() 98} 99 100// StreamingTranslateSpeech performs bidirectional streaming speech translation: receive results while 101// sending audio. This method is only available via the gRPC API (not REST). 102func (c *SpeechTranslationClient) StreamingTranslateSpeech(ctx context.Context, opts ...gax.CallOption) (mediatranslationpb.SpeechTranslationService_StreamingTranslateSpeechClient, error) { 103 return c.internalClient.StreamingTranslateSpeech(ctx, opts...) 104} 105 106// speechTranslationGRPCClient is a client for interacting with Media Translation API over gRPC transport. 107// 108// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 109type speechTranslationGRPCClient struct { 110 // Connection pool of gRPC connections to the service. 111 connPool gtransport.ConnPool 112 113 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 114 disableDeadlines bool 115 116 // Points back to the CallOptions field of the containing SpeechTranslationClient 117 CallOptions **SpeechTranslationCallOptions 118 119 // The gRPC API client. 120 speechTranslationClient mediatranslationpb.SpeechTranslationServiceClient 121 122 // The x-goog-* metadata to be sent with each request. 123 xGoogMetadata metadata.MD 124} 125 126// NewSpeechTranslationClient creates a new speech translation service client based on gRPC. 127// The returned client must be Closed when it is done being used to clean up its underlying connections. 128// 129// Provides translation from/to media types. 130func NewSpeechTranslationClient(ctx context.Context, opts ...option.ClientOption) (*SpeechTranslationClient, error) { 131 clientOpts := defaultSpeechTranslationGRPCClientOptions() 132 if newSpeechTranslationClientHook != nil { 133 hookOpts, err := newSpeechTranslationClientHook(ctx, clientHookParams{}) 134 if err != nil { 135 return nil, err 136 } 137 clientOpts = append(clientOpts, hookOpts...) 138 } 139 140 disableDeadlines, err := checkDisableDeadlines() 141 if err != nil { 142 return nil, err 143 } 144 145 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 146 if err != nil { 147 return nil, err 148 } 149 client := SpeechTranslationClient{CallOptions: defaultSpeechTranslationCallOptions()} 150 151 c := &speechTranslationGRPCClient{ 152 connPool: connPool, 153 disableDeadlines: disableDeadlines, 154 speechTranslationClient: mediatranslationpb.NewSpeechTranslationServiceClient(connPool), 155 CallOptions: &client.CallOptions, 156 } 157 c.setGoogleClientInfo() 158 159 client.internalClient = c 160 161 return &client, nil 162} 163 164// Connection returns a connection to the API service. 165// 166// Deprecated. 167func (c *speechTranslationGRPCClient) Connection() *grpc.ClientConn { 168 return c.connPool.Conn() 169} 170 171// setGoogleClientInfo sets the name and version of the application in 172// the `x-goog-api-client` header passed on each request. Intended for 173// use by Google-written clients. 174func (c *speechTranslationGRPCClient) setGoogleClientInfo(keyval ...string) { 175 kv := append([]string{"gl-go", versionGo()}, keyval...) 176 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 177 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 178} 179 180// Close closes the connection to the API service. The user should invoke this when 181// the client is no longer required. 182func (c *speechTranslationGRPCClient) Close() error { 183 return c.connPool.Close() 184} 185 186func (c *speechTranslationGRPCClient) StreamingTranslateSpeech(ctx context.Context, opts ...gax.CallOption) (mediatranslationpb.SpeechTranslationService_StreamingTranslateSpeechClient, error) { 187 ctx = insertMetadata(ctx, c.xGoogMetadata) 188 var resp mediatranslationpb.SpeechTranslationService_StreamingTranslateSpeechClient 189 opts = append((*c.CallOptions).StreamingTranslateSpeech[0:len((*c.CallOptions).StreamingTranslateSpeech):len((*c.CallOptions).StreamingTranslateSpeech)], opts...) 190 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 191 var err error 192 resp, err = c.speechTranslationClient.StreamingTranslateSpeech(ctx, settings.GRPC...) 193 return err 194 }, opts...) 195 if err != nil { 196 return nil, err 197 } 198 return resp, nil 199} 200