Pick a voice from the available catalog, request a streaming text-to-speech response for low-latency playback, and save the returned audio stream.
This example assumes using ElevenLabs; is in scope and apiKey contains your ElevenLabs API key.
1 2 3 4 5 6 7 8 9101112131415161718192021
usingvarclient=newElevenLabsClient(apiKey);// Choose a voice to synthesize with.varvoices=awaitclient.Voices.GetAllAsync();varvoice=voices.Voices[0];conststringtext="This audio is streamed for low-latency playback.";Console.WriteLine($"Using voice: {voice.Name} ({voice.VoiceId})");Console.WriteLine($"Input text: {text}");// Request streaming speech audio.usingvarstreamedAudio=awaitclient.TextToSpeech2.StreamAsync(voiceId:voice.VoiceId,text:text,modelId:"eleven_multilingual_v2",outputFormat:TextToSpeechStreamOutputFormat.Mp32205032);// Persist the result to a local file.awaitusingvaroutput=File.Create("streamed-output.mp3");awaitstreamedAudio.CopyToAsync(output);Console.WriteLine($"Saved {output.Length} bytes to streamed-output.mp3");