usingvarclient=newCartesiaClient(apiKey);// Check the API status to verify connectivity.varresponse=awaitclient.ApiStatus.ApiStatusGetAsync(cartesiaVersion:ApiStatusGetCartesiaVersion.x20251104);
Speech To Text Client Get Text Async
1 2 3 4 5 6 7 8 910111213141516
usingvarapi=newCartesiaClient(apiKey);ISpeechToTextClientspeechClient=api;// Transcribe audio using the MEAI ISpeechToTextClient interface.// Cartesia processes the audio synchronously — no polling required.usingvarhttpClient=newHttpClient();awaitusingvaraudioStream=awaithttpClient.GetStreamAsync("https://cdn.openai.com/API/docs/audio/alloy.wav");varms=newMemoryStream();awaitaudioStream.CopyToAsync(ms);ms.Position=0;varresponse=awaitspeechClient.GetTextAsync(ms);Console.WriteLine($"Text: {response.Text}");
Speech To Text Client Get Service Metadata
12345
usingvarapi=newCartesiaClient("dummy-key");ISpeechToTextClientspeechClient=api;// Retrieve metadata about the speech-to-text provider.varmetadata=speechClient.GetService<SpeechToTextClientMetadata>();
Speech To Text Client Get Service Self
12345
usingvarapi=newCartesiaClient("dummy-key");ISpeechToTextClientspeechClient=api;// Access the underlying CartesiaClient from the MEAI interface.varself=speechClient.GetService<CartesiaClient>();
Text To Speech Client Get Service Metadata
12345
usingvarapi=newCartesiaClient("dummy-key");ITextToSpeechClientspeechClient=api;// Retrieve metadata about the text-to-speech provider.varmetadata=speechClient.GetService<TextToSpeechClientMetadata>();
varhandler=newTtsSseResponseHandler();usingvarapi=newCartesiaClient("dummy-key",newHttpClient(handler){BaseAddress=newUri(CartesiaClient.DefaultBaseUrl),});varrequest=newTTSSSERequest{ModelId=TTSModel.Sonic35,Transcript="Hello from Cartesia.",Voice=newTTSRequestVoiceSpecifier{Mode=TTSRequestVoiceSpecifierMode.Id,Id="694f9389-aac1-45b6-b726-9d9369183238",},OutputFormat=newSSEOutputFormat{Container=SSEOutputFormatContainer.Raw,Encoding=RawEncoding.PcmS16le,SampleRate=24000,},ContextId="ctx-1",};varevents=newList<CartesiaTtsSseEvent>();// StreamTtsSseAsync yields events as the SSE response is read and decodes chunk audio bytes.awaitforeach(var@eventinapi.StreamTtsSseAsync(request)){events.Add(@event);}