A clean and minimalistic .NET client library for the FastWhisper speech-to-text API.
$ dotnet add package FastWhisper.ClientA clean, minimalistic .NET client library for the FastWhisper API.
dotnet add package FastWhisper.Client
using FastWhisper.Client;
using FastWhisper.Client.Models;
// Create client
using var client = new FastWhisperClient("http://127.0.0.1:8000");
// Check health
var health = await client.GetHealthAsync();
Console.WriteLine($"Status: {health.Status}, Model Loaded: {health.ModelLoaded}");
// Transcribe audio
await using var audioStream = File.OpenRead("audio.mp3");
var transcription = await client.TranscribeAsync(
audioStream,
"audio.mp3",
language: "en",
timestamp: TimestampGranularity.Chunk
);
Console.WriteLine($"Text: {transcription.Text}");
foreach (var chunk in transcription.Chunks)
{
Console.WriteLine($"[{chunk.Timestamp[0]:F2}s - {chunk.Timestamp[1]:F2}s]: {chunk.Text}");
}
var health = await client.GetHealthAsync();
Transcribes audio to text in the original language.
var transcription = await client.TranscribeAsync(
audioStream,
fileName: "audio.mp3",
language: "en", // Optional: null for auto-detect
timestamp: TimestampGranularity.Chunk, // Chunk or Word
cancellationToken: cancellationToken
);
Translates audio to English text.
var translation = await client.TranslateAsync(
audioStream,
fileName: "audio.mp3",
timestamp: TimestampGranularity.Word,
cancellationToken: cancellationToken
);
TimestampGranularity.Chunk (default): Segment-level timestamps (phrases/segments)TimestampGranularity.Word: Word-level timestamps (finer granularity)Supported language codes (ISO 639-1): en, fr, es, de, it, pt, nl, ja, zh, etc.
Pass null to the language parameter for automatic language detection.
using var client = new FastWhisperClient("http://127.0.0.1:8000");For dependency injection or custom configuration:
var httpClient = new HttpClient
{
BaseAddress = new Uri("http://127.0.0.1:8000"),
Timeout = TimeSpan.FromMinutes(5)
};
var client = new FastWhisperClient(httpClient, disposeHttpClient: false);try
{
var transcription = await client.TranscribeAsync(audioStream, "audio.mp3");
}
catch (HttpRequestException ex)
{
Console.WriteLine($"API request failed: {ex.Message}");
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"Response parsing failed: {ex.Message}");
}MIT License - see LICENSE file for details.