This example assumes using Xai; is in scope and apiKey contains your Xai API key.
1 2 3 4 5 6 7 8 910111213141516
varcustomVoiceId=Environment.GetEnvironmentVariable("XAI_CUSTOM_VOICE_ID")is{Length:>0}value?value:thrownewAssertInconclusiveException("XAI_CUSTOM_VOICE_ID environment variable is not found.");varclient=newXaiClient(apiKey);// Retrieve metadata for a custom voice owned by your team.varcustomVoice=awaitclient.CustomVoices.GetCustomVoiceAsync(customVoiceId);// Use the custom voice ID anywhere a built-in TTS voice ID is accepted.byte[]audioBytes=awaitclient.Audio.CreateTextToSpeechAsync(text:"Hello from my custom xAI voice.",language:"en",voiceId:customVoice.VoiceId);