Use this file to discover all available pages before exploring further.
The official C# library for the Typecast API. Convert text to lifelike speech using AI-powered voices.Supports .NET Standard 2.0+, .NET 6+, Unity (via NuGetForUnity), and Blazor applications. Full async/await support with synchronous alternatives.
Make sure you have the latest version installed. You can check with dotnet list package. Update with dotnet add package typecast-csharp to get the latest version.
Set your API key via environment variable or constructor:
// Using environment variable (TYPECAST_API_KEY)using var client = new TypecastClient();// Or pass directlyusing var client = new TypecastClient("your-api-key-here");// Or use configuration objectvar config = new TypecastClientConfig{ ApiKey = "your-api-key-here", TimeoutSeconds = 60 // Optional, default: 30};using var client = new TypecastClient(config);
ssfm-v30 offers two emotion control modes: Preset and Smart.
Smart Mode
Preset Mode
Let the AI infer emotion from context:
var request = new TTSRequest("Everything is going to be okay.", voiceId, TTSModel.SsfmV30){ Language = LanguageCode.English, Prompt = new SmartPrompt( previousText: "I just got the best news!", nextText: "I can't wait to celebrate!" )};var response = await client.TextToSpeechAsync(request);
Explicitly set emotion with preset values:
var request = new TTSRequest("I am so excited to show you these features!", voiceId, TTSModel.SsfmV30){ Language = LanguageCode.English, Prompt = new PresetPrompt( emotionPreset: EmotionPreset.Happy, emotionIntensity: 1.5 // Range: 0.0 to 2.0 )};var response = await client.TextToSpeechAsync(request);
The SDK supports 37 languages with automatic language detection:
// Auto-detect language (recommended)var request = new TTSRequest("こんにちは。お元気ですか。", voiceId, TTSModel.SsfmV30);var response = await client.TextToSpeechAsync(request);// Or specify language explicitlyvar koreanRequest = new TTSRequest("안녕하세요. 반갑습니다.", voiceId, TTSModel.SsfmV30){ Language = LanguageCode.Korean // ISO 639-3 language code};await response.SaveToFileAsync("output.wav");
Stream audio chunks in real-time for low-latency playback:
// Stream and extract raw PCM (skip 44-byte WAV header)using var stream = await client.TextToSpeechStreamAsync(request);var buffer = new byte[8192];bool first = true;while (true){ int bytesRead = await stream.ReadAsync(buffer); if (bytesRead == 0) break; ReadOnlySpan<byte> pcm = buffer.AsSpan(0, bytesRead); if (first) { pcm = pcm[44..]; // Skip WAV header first = false; } // pcm is raw 16-bit mono PCM at 32000 Hz // Feed to your audio output (e.g. NAudio)}
WAV streaming format: 32000 Hz, 16-bit, mono PCM. The first chunk includes a 44-byte WAV header (size = 0xFFFFFFFF); subsequent chunks are raw PCM only. For MP3: 320 kbps, 44100 Hz, each chunk is independently decodable. The streaming endpoint does not support Volume or TargetLufs.
TextToSpeechWithTimestampsAsync() wraps POST /v1/text-to-speech/with-timestamps and returns the audio together with per-word and per-character alignment data — useful for karaoke highlights, subtitle generation, and lip-sync applications.
using Typecast;using Typecast.Models;using var client = new TypecastClient("YOUR_API_KEY");var request = new TTSRequestWithTimestamps( text: "Hello. How are you?", voiceId: "tc_60e5426de8b95f1d3000d7b5", model: TTSModel.SsfmV30);var result = await client.TextToSpeechWithTimestampsAsync(request);await result.SaveToFileAsync("output.wav");Console.WriteLine($"Duration: {result.AudioDuration}s");foreach (var word in result.Words){ Console.WriteLine($" [{word.StartTime:F3}s – {word.EndTime:F3}s] {word.Text}");}
Set Granularity = Granularity.Word (default) or Granularity = Granularity.Char to control the alignment unit.
// Character-level alignment — required for Japanese / Chinesevar request = new TTSRequestWithTimestamps( text: "Hello. How are you?", voiceId: "tc_60e5426de8b95f1d3000d7b5", model: TTSModel.SsfmV30){ Granularity = Granularity.Char};
Japanese / Chinese: Word-level segmentation is not meaningful for languages without whitespace delimiters (jpn, zho). Use Granularity.Char for these languages to get character-level alignment.