Class VoicesClient
- Namespace
- GenerativeAI.Clients
- Assembly
- GenerativeAI.dll
A client for the Voices API (/voices): design voices from a prompt, remix an existing voice, replicate a
voice from recorded audio, and list custom and prebuilt voices for text-to-speech. Follows python-genai's
client.voices.
public class VoicesClient : AgentApiClientBase
- Inheritance
-
VoicesClient
- Inherited Members
- Extension Methods
Constructors
VoicesClient(IPlatformAdapter, HttpClient?, ILogger?)
Initializes a new instance of the VoicesClient class.
public VoicesClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)
Parameters
platformIPlatformAdapterThe platform adapter (Google AI or Vertex AI).
httpClientHttpClientOptional HTTP client.
loggerILoggerOptional logger.
Methods
CreateAsync(CreateVoiceRequest, CancellationToken)
Creates a voice (POST /voices).
public Task<Voice> CreateAsync(CreateVoiceRequest request, CancellationToken cancellationToken = default)
Parameters
requestCreateVoiceRequestThe request.
cancellationTokenCancellationTokenA cancellation token.
Returns
CreateAsync(Voice, bool?, CancellationToken)
Creates a voice (POST /voices).
public Task<Voice> CreateAsync(Voice voice, bool? store = null, CancellationToken cancellationToken = default)
Parameters
voiceVoiceThe voice to create.
storebool?Whether to store the voice for reuse.
cancellationTokenCancellationTokenA cancellation token.
Returns
DeleteAsync(string, CancellationToken)
Deletes a custom voice (DELETE /voices/{id}).
public Task<DeleteVoiceResponse> DeleteAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe voice ID.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<DeleteVoiceResponse>
The (empty) delete response.
DesignAsync(string, string?, bool?, CancellationToken)
Designs a voice from a text description (a prompted voice).
public Task<Voice> DesignAsync(string prompt, string? displayName = null, bool? store = null, CancellationToken cancellationToken = default)
Parameters
promptstringThe description of the voice.
displayNamestringOptional display name.
storebool?Whether to store the voice for reuse.
cancellationTokenCancellationTokenA cancellation token.
Returns
GetAsync(string, CancellationToken)
Gets a voice (GET /voices/{id}).
public Task<Voice> GetAsync(string id, CancellationToken cancellationToken = default)
Parameters
idstringThe voice ID (a
voices/prefix is accepted).cancellationTokenCancellationTokenA cancellation token.
Returns
ListAllAsync(ListVoicesOptions?, int?, CancellationToken)
Lists all voices matching options, following page tokens.
public IAsyncEnumerable<Voice> ListAllAsync(ListVoicesOptions? options = null, int? pageSize = null, CancellationToken cancellationToken = default)
Parameters
optionsListVoicesOptionsOptional filters.
pageSizeint?The page size.
cancellationTokenCancellationTokenA cancellation token.
Returns
- IAsyncEnumerable<Voice>
The voices.
ListAsync(ListVoicesOptions?, int?, string?, CancellationToken)
Lists one page of voices (GET /voices): custom voices (newest first) followed by prebuilt voices.
public Task<ListVoicesResponse> ListAsync(ListVoicesOptions? options = null, int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)
Parameters
optionsListVoicesOptionsOptional filters.
pageSizeint?The maximum number of voices per page (server default 50, max 1000).
pageTokenstringThe page token of a previous call (filters must match).
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<ListVoicesResponse>
The page.
RemixAsync(string, string, string?, bool?, CancellationToken)
Remixes an existing voice according to instructions (a prompted voice with a base voice).
public Task<Voice> RemixAsync(string baseVoice, string instructions, string? displayName = null, bool? store = null, CancellationToken cancellationToken = default)
Parameters
baseVoicestringThe voice to remix.
instructionsstringHow to change the voice.
displayNamestringOptional display name.
storebool?Whether to store the voice for reuse.
cancellationTokenCancellationTokenA cancellation token.
Returns
ReplicateAsync(VoiceAudioData, VoiceAudioData, string?, bool?, CancellationToken)
Replicates a voice from recorded audio (a replicated voice).
public Task<Voice> ReplicateAsync(VoiceAudioData sourceAudio, VoiceAudioData consentAudio, string? displayName = null, bool? store = null, CancellationToken cancellationToken = default)
Parameters
sourceAudioVoiceAudioDataAudio of the voice to replicate.
consentAudioVoiceAudioDataAudio of the speaker consenting to the replication.
displayNamestringOptional display name.
storebool?Whether to store the voice for reuse.
cancellationTokenCancellationTokenA cancellation token.