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 defaultSpeechTranslationClientOptions() []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		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
46		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
47			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
48	}
49}
50
51func defaultSpeechTranslationCallOptions() *SpeechTranslationCallOptions {
52	return &SpeechTranslationCallOptions{
53		StreamingTranslateSpeech: []gax.CallOption{},
54	}
55}
56
57// SpeechTranslationClient is a client for interacting with Media Translation API.
58//
59// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
60type SpeechTranslationClient struct {
61	// Connection pool of gRPC connections to the service.
62	connPool gtransport.ConnPool
63
64	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
65	disableDeadlines bool
66
67	// The gRPC API client.
68	speechTranslationClient mediatranslationpb.SpeechTranslationServiceClient
69
70	// The call options for this service.
71	CallOptions *SpeechTranslationCallOptions
72
73	// The x-goog-* metadata to be sent with each request.
74	xGoogMetadata metadata.MD
75}
76
77// NewSpeechTranslationClient creates a new speech translation service client.
78//
79// Provides translation from/to media types.
80func NewSpeechTranslationClient(ctx context.Context, opts ...option.ClientOption) (*SpeechTranslationClient, error) {
81	clientOpts := defaultSpeechTranslationClientOptions()
82
83	if newSpeechTranslationClientHook != nil {
84		hookOpts, err := newSpeechTranslationClientHook(ctx, clientHookParams{})
85		if err != nil {
86			return nil, err
87		}
88		clientOpts = append(clientOpts, hookOpts...)
89	}
90
91	disableDeadlines, err := checkDisableDeadlines()
92	if err != nil {
93		return nil, err
94	}
95
96	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
97	if err != nil {
98		return nil, err
99	}
100	c := &SpeechTranslationClient{
101		connPool:         connPool,
102		disableDeadlines: disableDeadlines,
103		CallOptions:      defaultSpeechTranslationCallOptions(),
104
105		speechTranslationClient: mediatranslationpb.NewSpeechTranslationServiceClient(connPool),
106	}
107	c.setGoogleClientInfo()
108
109	return c, nil
110}
111
112// Connection returns a connection to the API service.
113//
114// Deprecated.
115func (c *SpeechTranslationClient) Connection() *grpc.ClientConn {
116	return c.connPool.Conn()
117}
118
119// Close closes the connection to the API service. The user should invoke this when
120// the client is no longer required.
121func (c *SpeechTranslationClient) Close() error {
122	return c.connPool.Close()
123}
124
125// setGoogleClientInfo sets the name and version of the application in
126// the `x-goog-api-client` header passed on each request. Intended for
127// use by Google-written clients.
128func (c *SpeechTranslationClient) setGoogleClientInfo(keyval ...string) {
129	kv := append([]string{"gl-go", versionGo()}, keyval...)
130	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
131	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
132}
133
134// StreamingTranslateSpeech performs bidirectional streaming speech translation: receive results while
135// sending audio. This method is only available via the gRPC API (not REST).
136func (c *SpeechTranslationClient) StreamingTranslateSpeech(ctx context.Context, opts ...gax.CallOption) (mediatranslationpb.SpeechTranslationService_StreamingTranslateSpeechClient, error) {
137	ctx = insertMetadata(ctx, c.xGoogMetadata)
138	opts = append(c.CallOptions.StreamingTranslateSpeech[0:len(c.CallOptions.StreamingTranslateSpeech):len(c.CallOptions.StreamingTranslateSpeech)], opts...)
139	var resp mediatranslationpb.SpeechTranslationService_StreamingTranslateSpeechClient
140	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
141		var err error
142		resp, err = c.speechTranslationClient.StreamingTranslateSpeech(ctx, settings.GRPC...)
143		return err
144	}, opts...)
145	if err != nil {
146		return nil, err
147	}
148	return resp, nil
149}
150