public abstract class TextToSpeechClient
TextToSpeech client wrapper, for convenient use.
Derived Types
Namespace
Google.Cloud.TextToSpeech.V1Assembly
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 | |
---|---|
Type | Description |
String |
DefaultScopes
public static IReadOnlyList<string> DefaultScopes { get; }
The default TextToSpeech scopes.
Property Value | |
---|---|
Type | Description |
IReadOnlyList<String> |
The default TextToSpeech scopes are:
GrpcClient
public virtual TextToSpeech.TextToSpeechClient GrpcClient { get; }
The underlying gRPC TextToSpeech client
Property Value | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
cancellationToken | CancellationToken The CancellationToken to use while creating the client. |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
request | ListVoicesRequest The request object containing all of the parameters for the API call. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
ListVoicesResponse | The RPC response. |
// 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 | |
---|---|
Name | Description |
languageCode | String 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 |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
ListVoicesResponse | The RPC response. |
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 | |
---|---|
Name | Description |
request | ListVoicesRequest The request object containing all of the parameters for the API call. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<ListVoicesResponse> | A Task containing the RPC response. |
// 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 | |
---|---|
Name | Description |
request | ListVoicesRequest The request object containing all of the parameters for the API call. |
cancellationToken | CancellationToken A CancellationToken to use for this RPC. |
Returns | |
---|---|
Type | Description |
Task<ListVoicesResponse> | A Task containing the RPC response. |
// 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 | |
---|---|
Name | Description |
languageCode | String 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 |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<ListVoicesResponse> | A Task containing the RPC response. |
// 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 | |
---|---|
Name | Description |
languageCode | String 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 |
cancellationToken | CancellationToken A CancellationToken to use for this RPC. |
Returns | |
---|---|
Type | Description |
Task<ListVoicesResponse> | A Task containing the RPC response. |
// 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 | |
---|---|
Type | Description |
Task | A task representing the asynchronous shutdown operation. |
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 | |
---|---|
Name | Description |
input | SynthesisInput Required. The Synthesizer requires either plain text or SSML as input. |
voice | VoiceSelectionParams Required. The desired voice of the synthesized audio. |
audioConfig | AudioConfig Required. The configuration of the synthesized audio. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
SynthesizeSpeechResponse | The RPC response. |
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 | |
---|---|
Name | Description |
request | SynthesizeSpeechRequest The request object containing all of the parameters for the API call. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
SynthesizeSpeechResponse | The RPC response. |
// 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 | |
---|---|
Name | Description |
input | SynthesisInput Required. The Synthesizer requires either plain text or SSML as input. |
voice | VoiceSelectionParams Required. The desired voice of the synthesized audio. |
audioConfig | AudioConfig Required. The configuration of the synthesized audio. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<SynthesizeSpeechResponse> | A Task containing the RPC response. |
// 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 | |
---|---|
Name | Description |
input | SynthesisInput Required. The Synthesizer requires either plain text or SSML as input. |
voice | VoiceSelectionParams Required. The desired voice of the synthesized audio. |
audioConfig | AudioConfig Required. The configuration of the synthesized audio. |
cancellationToken | CancellationToken A CancellationToken to use for this RPC. |
Returns | |
---|---|
Type | Description |
Task<SynthesizeSpeechResponse> | A Task containing the RPC response. |
// 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 | |
---|---|
Name | Description |
request | SynthesizeSpeechRequest The request object containing all of the parameters for the API call. |
callSettings | CallSettings If not null, applies overrides to this RPC call. |
Returns | |
---|---|
Type | Description |
Task<SynthesizeSpeechResponse> | A Task containing the RPC response. |
// 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 | |
---|---|
Name | Description |
request | SynthesizeSpeechRequest The request object containing all of the parameters for the API call. |
cancellationToken | CancellationToken A CancellationToken to use for this RPC. |
Returns | |
---|---|
Type | Description |
Task<SynthesizeSpeechResponse> | A Task containing the RPC response. |
// 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);