Class TextToSpeechClient (2.3.0)

public abstract class TextToSpeechClient

TextToSpeech client wrapper, for convenient use.

Inheritance

Object > TextToSpeechClient

Derived Types

Namespace

Google.Cloud.TextToSpeech.V1

Assembly

Google.Cloud.TextToSpeech.V1.dll

Remarks

Service that implements Google Cloud Text-to-Speech API.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

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

Property Value
TypeDescription
String

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default TextToSpeech scopes.

Property Value
TypeDescription
IReadOnlyList<String>
Remarks

The default TextToSpeech scopes are:

GrpcClient

public virtual TextToSpeech.TextToSpeechClient GrpcClient { get; }

The underlying gRPC TextToSpeech client

Property Value
TypeDescription
TextToSpeech.TextToSpeechClient

Methods

Create()

public static TextToSpeechClient Create()

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

Returns
TypeDescription
TextToSpeechClient

The created TextToSpeechClient.

CreateAsync(CancellationToken)

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

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

Parameter
NameDescription
cancellationTokenCancellationToken

The CancellationToken to use while creating the client.

Returns
TypeDescription
Task<TextToSpeechClient>

The task representing the created TextToSpeechClient.

ListVoices(ListVoicesRequest, CallSettings)

public virtual ListVoicesResponse ListVoices(ListVoicesRequest request, CallSettings callSettings = null)

Returns a list of Voice supported for synthesis.

Parameters
NameDescription
requestListVoicesRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
ListVoicesResponse

The RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = TextToSpeechClient.Create();
// Initialize request argument(s)
ListVoicesRequest request = new ListVoicesRequest { LanguageCode = "", };
// Make the request
ListVoicesResponse response = textToSpeechClient.ListVoices(request);

ListVoices(String, CallSettings)

public virtual ListVoicesResponse ListVoices(string languageCode, CallSettings callSettings = null)

Returns a list of Voice supported for synthesis.

Parameters
NameDescription
languageCodeString

Optional. Recommended. BCP-47 language tag. If specified, the ListVoices call will only return voices that can be used to synthesize this language_code. E.g. when specifying "en-NZ", you will get supported "en-*" voices; when specifying "no", you will get supported "no-*" (Norwegian) and "nb-*" (Norwegian Bokmal) voices; specifying "zh" will also get supported "cmn-*" voices; specifying "zh-hk" will also get supported "yue-*" voices.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
ListVoicesResponse

The RPC response.

Example
TextToSpeechClient client = TextToSpeechClient.Create();
ListVoicesResponse response = client.ListVoices("en");
foreach (Voice voice in response.Voices)
{
    Console.WriteLine($"{voice.Name} ({voice.SsmlGender}); Language codes: {string.Join(", ", voice.LanguageCodes)}");
}

ListVoicesAsync(ListVoicesRequest, CallSettings)

public virtual Task<ListVoicesResponse> ListVoicesAsync(ListVoicesRequest request, CallSettings callSettings = null)

Returns a list of Voice supported for synthesis.

Parameters
NameDescription
requestListVoicesRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<ListVoicesResponse>

A Task containing the RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
ListVoicesRequest request = new ListVoicesRequest { LanguageCode = "", };
// Make the request
ListVoicesResponse response = await textToSpeechClient.ListVoicesAsync(request);

ListVoicesAsync(ListVoicesRequest, CancellationToken)

public virtual Task<ListVoicesResponse> ListVoicesAsync(ListVoicesRequest request, CancellationToken cancellationToken)

Returns a list of Voice supported for synthesis.

Parameters
NameDescription
requestListVoicesRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task<ListVoicesResponse>

A Task containing the RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
ListVoicesRequest request = new ListVoicesRequest { LanguageCode = "", };
// Make the request
ListVoicesResponse response = await textToSpeechClient.ListVoicesAsync(request);

ListVoicesAsync(String, CallSettings)

public virtual Task<ListVoicesResponse> ListVoicesAsync(string languageCode, CallSettings callSettings = null)

Returns a list of Voice supported for synthesis.

Parameters
NameDescription
languageCodeString

Optional. Recommended. BCP-47 language tag. If specified, the ListVoices call will only return voices that can be used to synthesize this language_code. E.g. when specifying "en-NZ", you will get supported "en-*" voices; when specifying "no", you will get supported "no-*" (Norwegian) and "nb-*" (Norwegian Bokmal) voices; specifying "zh" will also get supported "cmn-*" voices; specifying "zh-hk" will also get supported "yue-*" voices.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<ListVoicesResponse>

A Task containing the RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
string languageCode = "";
// Make the request
ListVoicesResponse response = await textToSpeechClient.ListVoicesAsync(languageCode);

ListVoicesAsync(String, CancellationToken)

public virtual Task<ListVoicesResponse> ListVoicesAsync(string languageCode, CancellationToken cancellationToken)

Returns a list of Voice supported for synthesis.

Parameters
NameDescription
languageCodeString

Optional. Recommended. BCP-47 language tag. If specified, the ListVoices call will only return voices that can be used to synthesize this language_code. E.g. when specifying "en-NZ", you will get supported "en-*" voices; when specifying "no", you will get supported "no-*" (Norwegian) and "nb-*" (Norwegian Bokmal) voices; specifying "zh" will also get supported "cmn-*" voices; specifying "zh-hk" will also get supported "yue-*" voices.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task<ListVoicesResponse>

A Task containing the RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
string languageCode = "";
// Make the request
ListVoicesResponse response = await textToSpeechClient.ListVoicesAsync(languageCode);

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.

SynthesizeSpeech(SynthesisInput, VoiceSelectionParams, AudioConfig, CallSettings)

public virtual SynthesizeSpeechResponse SynthesizeSpeech(SynthesisInput input, VoiceSelectionParams voice, AudioConfig audioConfig, CallSettings callSettings = null)

Synthesizes speech synchronously: receive results after all text input has been processed.

Parameters
NameDescription
inputSynthesisInput

Required. The Synthesizer requires either plain text or SSML as input.

voiceVoiceSelectionParams

Required. The desired voice of the synthesized audio.

audioConfigAudioConfig

Required. The configuration of the synthesized audio.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
SynthesizeSpeechResponse

The RPC response.

Example
TextToSpeechClient client = TextToSpeechClient.Create();
// The input can be provided as text or SSML.
SynthesisInput input = new SynthesisInput
{
    Text = "This is a demonstration of the Google Cloud Text-to-Speech API"
};
// You can specify a particular voice, or ask the server to pick based
// on specified criteria.
VoiceSelectionParams voiceSelection = new VoiceSelectionParams
{
    LanguageCode = "en-US",
    SsmlGender = SsmlVoiceGender.Female
};
// The audio configuration determines the output format and speaking rate.
AudioConfig audioConfig = new AudioConfig
{
    AudioEncoding = AudioEncoding.Mp3
};
SynthesizeSpeechResponse response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);
using (Stream output = File.Create("sample.mp3"))
{
    // response.AudioContent is a ByteString. This can easily be converted into
    // a byte array or written to a stream.
    response.AudioContent.WriteTo(output);
}

SynthesizeSpeech(SynthesizeSpeechRequest, CallSettings)

public virtual SynthesizeSpeechResponse SynthesizeSpeech(SynthesizeSpeechRequest request, CallSettings callSettings = null)

Synthesizes speech synchronously: receive results after all text input has been processed.

Parameters
NameDescription
requestSynthesizeSpeechRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
SynthesizeSpeechResponse

The RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = TextToSpeechClient.Create();
// Initialize request argument(s)
SynthesizeSpeechRequest request = new SynthesizeSpeechRequest
{
    Input = new SynthesisInput(),
    Voice = new VoiceSelectionParams(),
    AudioConfig = new AudioConfig(),
};
// Make the request
SynthesizeSpeechResponse response = textToSpeechClient.SynthesizeSpeech(request);

SynthesizeSpeechAsync(SynthesisInput, VoiceSelectionParams, AudioConfig, CallSettings)

public virtual Task<SynthesizeSpeechResponse> SynthesizeSpeechAsync(SynthesisInput input, VoiceSelectionParams voice, AudioConfig audioConfig, CallSettings callSettings = null)

Synthesizes speech synchronously: receive results after all text input has been processed.

Parameters
NameDescription
inputSynthesisInput

Required. The Synthesizer requires either plain text or SSML as input.

voiceVoiceSelectionParams

Required. The desired voice of the synthesized audio.

audioConfigAudioConfig

Required. The configuration of the synthesized audio.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<SynthesizeSpeechResponse>

A Task containing the RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
SynthesisInput input = new SynthesisInput();
VoiceSelectionParams voice = new VoiceSelectionParams();
AudioConfig audioConfig = new AudioConfig();
// Make the request
SynthesizeSpeechResponse response = await textToSpeechClient.SynthesizeSpeechAsync(input, voice, audioConfig);

SynthesizeSpeechAsync(SynthesisInput, VoiceSelectionParams, AudioConfig, CancellationToken)

public virtual Task<SynthesizeSpeechResponse> SynthesizeSpeechAsync(SynthesisInput input, VoiceSelectionParams voice, AudioConfig audioConfig, CancellationToken cancellationToken)

Synthesizes speech synchronously: receive results after all text input has been processed.

Parameters
NameDescription
inputSynthesisInput

Required. The Synthesizer requires either plain text or SSML as input.

voiceVoiceSelectionParams

Required. The desired voice of the synthesized audio.

audioConfigAudioConfig

Required. The configuration of the synthesized audio.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task<SynthesizeSpeechResponse>

A Task containing the RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
SynthesisInput input = new SynthesisInput();
VoiceSelectionParams voice = new VoiceSelectionParams();
AudioConfig audioConfig = new AudioConfig();
// Make the request
SynthesizeSpeechResponse response = await textToSpeechClient.SynthesizeSpeechAsync(input, voice, audioConfig);

SynthesizeSpeechAsync(SynthesizeSpeechRequest, CallSettings)

public virtual Task<SynthesizeSpeechResponse> SynthesizeSpeechAsync(SynthesizeSpeechRequest request, CallSettings callSettings = null)

Synthesizes speech synchronously: receive results after all text input has been processed.

Parameters
NameDescription
requestSynthesizeSpeechRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<SynthesizeSpeechResponse>

A Task containing the RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
SynthesizeSpeechRequest request = new SynthesizeSpeechRequest
{
    Input = new SynthesisInput(),
    Voice = new VoiceSelectionParams(),
    AudioConfig = new AudioConfig(),
};
// Make the request
SynthesizeSpeechResponse response = await textToSpeechClient.SynthesizeSpeechAsync(request);

SynthesizeSpeechAsync(SynthesizeSpeechRequest, CancellationToken)

public virtual Task<SynthesizeSpeechResponse> SynthesizeSpeechAsync(SynthesizeSpeechRequest request, CancellationToken cancellationToken)

Synthesizes speech synchronously: receive results after all text input has been processed.

Parameters
NameDescription
requestSynthesizeSpeechRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task<SynthesizeSpeechResponse>

A Task containing the RPC response.

Example
// Create client
TextToSpeechClient textToSpeechClient = await TextToSpeechClient.CreateAsync();
// Initialize request argument(s)
SynthesizeSpeechRequest request = new SynthesizeSpeechRequest
{
    Input = new SynthesisInput(),
    Voice = new VoiceSelectionParams(),
    AudioConfig = new AudioConfig(),
};
// Make the request
SynthesizeSpeechResponse response = await textToSpeechClient.SynthesizeSpeechAsync(request);