Class SpeechTranslationServiceClient (2.0.0-beta01)

public abstract class SpeechTranslationServiceClient

SpeechTranslationService client wrapper, for convenient use.

Inheritance

Object > SpeechTranslationServiceClient

Namespace

Google.Cloud.MediaTranslation.V1Beta1

Assembly

Google.Cloud.MediaTranslation.V1Beta1.dll

Remarks

Provides translation from/to media types.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

The default endpoint for the SpeechTranslationService service, which is a host of "mediatranslation.googleapis.com" and a port of 443.

Property Value
TypeDescription
String

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default SpeechTranslationService scopes.

Property Value
TypeDescription
IReadOnlyList<String>
Remarks

The default SpeechTranslationService scopes are:

GrpcClient

public virtual SpeechTranslationService.SpeechTranslationServiceClient GrpcClient { get; }

The underlying gRPC SpeechTranslationService client

Property Value
TypeDescription
SpeechTranslationService.SpeechTranslationServiceClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
TypeDescription
ServiceMetadata

Methods

Create()

public static SpeechTranslationServiceClient Create()

Synchronously creates a SpeechTranslationServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use SpeechTranslationServiceClientBuilder.

Returns
TypeDescription
SpeechTranslationServiceClient

The created SpeechTranslationServiceClient.

CreateAsync(CancellationToken)

public static Task<SpeechTranslationServiceClient> CreateAsync(CancellationToken cancellationToken = default(CancellationToken))

Asynchronously creates a SpeechTranslationServiceClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use SpeechTranslationServiceClientBuilder.

Parameter
NameDescription
cancellationTokenCancellationToken

The CancellationToken to use while creating the client.

Returns
TypeDescription
Task<SpeechTranslationServiceClient>

The task representing the created SpeechTranslationServiceClient.

ShutdownDefaultChannelsAsync()

public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by Create() and CreateAsync(CancellationToken). Channels which weren't automatically created are not affected.

Returns
TypeDescription
Task

A task representing the asynchronous shutdown operation.

Remarks

After calling this method, further calls to Create() and CreateAsync(CancellationToken) will create new channels, which could in turn be shut down by another call to this method.

StreamingTranslateSpeech(CallSettings, BidirectionalStreamingSettings)

public virtual SpeechTranslationServiceClient.StreamingTranslateSpeechStream StreamingTranslateSpeech(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Performs bidirectional streaming speech translation: receive results while sending audio. This method is only available via the gRPC API (not REST).

Parameters
NameDescription
callSettingsCallSettings

If not null, applies overrides to this RPC call.

streamingSettingsBidirectionalStreamingSettings

If not null, applies streaming overrides to this RPC call.

Returns
TypeDescription
SpeechTranslationServiceClient.StreamingTranslateSpeechStream

The client-server stream.

Example
// Create client
SpeechTranslationServiceClient speechTranslationServiceClient = SpeechTranslationServiceClient.Create();
// Initialize streaming call, retrieving the stream object
SpeechTranslationServiceClient.StreamingTranslateSpeechStream response = speechTranslationServiceClient.StreamingTranslateSpeech();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<StreamingTranslateSpeechResponse> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        StreamingTranslateSpeechResponse responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    StreamingTranslateSpeechRequest request = new StreamingTranslateSpeechRequest
    {
        StreamingConfig = new StreamingTranslateSpeechConfig(),
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;