Skip to content
Shiny Controls v1.0 - The Ultra Control Suite for .NET MAUI & BlazorO...M...G!

OpenAI

Downloads NuGet downloads for Shiny.Speech.OpenAI
Frameworks
.NET
.NET MAUI
Operating Systems
Android
iOS
Windows

OpenAI provides powerful speech-to-text (Whisper / GPT-4o Transcribe) and text-to-speech models. This provider replaces the platform-native ISpeechToTextService and ITextToSpeechService registrations with OpenAI cloud implementations while still using platform-native audio capture and playback.

// In MauiProgram.cs
builder.Services.AddOpenAiSpeech("your-api-key");
// IAudioSource and IAudioPlayer are automatically registered for platform audio I/O

Or with a config object and selective services:

builder.Services.AddOpenAiSpeech(
new OpenAiSpeechConfig
{
ApiKey = "your-api-key",
SpeechToTextModel = "gpt-4o-transcribe",
TextToSpeechModel = "gpt-4o-mini-tts",
DefaultVoice = "alloy"
},
speechToText: true,
textToSpeech: true
);
public record OpenAiSpeechConfig
{
public required string ApiKey { get; init; }
public string SpeechToTextModel { get; init; } = "gpt-4o-transcribe";
public string TextToSpeechModel { get; init; } = "gpt-4o-mini-tts";
public string DefaultVoice { get; init; } = "alloy";
}
Property Description Default
ApiKey Your OpenAI API key (required)
SpeechToTextModel The model to use for transcription gpt-4o-transcribe
TextToSpeechModel The model to use for speech synthesis gpt-4o-mini-tts
DefaultVoice Voice ID to use when none specified in TextToSpeechOptions alloy

OpenAI provides the following built-in voices:

Voice Description
alloy Neutral, balanced
ash Warm, conversational
ballad Soft, gentle
coral Clear, friendly
echo Smooth, resonant
fable Expressive, animated
onyx Deep, authoritative
nova Bright, energetic
sage Calm, measured
shimmer Light, upbeat

Once registered, inject and use ISpeechToTextService and ITextToSpeechService exactly as you would with platform-native speech — the API is identical:

public class MyViewModel(ISpeechToTextService stt, ITextToSpeechService tts)
{
async Task ListenAndRespond(CancellationToken ct)
{
var text = await stt.ListenUntilSilence(cancellationToken: ct);
if (text != null)
await tts.SpeakAsync($"You said: {text}");
}
async Task SpeakWithVoice()
{
var voices = await tts.GetVoicesAsync();
var voice = voices.FirstOrDefault(v => v.Name == "Nova");
if (voice != null)
{
await tts.SpeakAsync("Hello from OpenAI!", new TextToSpeechOptions
{
Voice = voice,
SpeechRate = 1.2f
});
}
}
}

OpenAI takes delivery direction as natural language via instructions, so a portable SpeechTone is rendered as a sentence and any bracketed annotations in the text are stripped rather than spoken aloud:

await tts.SpeakAsync("We just shipped it.", new TextToSpeechOptions
{
Tone = new SpeechTone
{
Emotion = SpeechEmotion.Excited,
Instructions = "Sound like you're sharing good news."
}
});
// -> instructions: "Speak in an excited, energetic tone. Sound like you're sharing good news."

The emotion becomes a lead sentence and your Instructions follow it, so the specific direction refines the general one. This needs an instruction-aware model — set TextToSpeechModel = "gpt-4o-mini-tts"; the older tts-1 models ignore the field. Intensity has no OpenAI equivalent and is ignored.

You can register OpenAI for just one service:

// OpenAI STT only (use platform-native TTS)
builder.Services.AddTextToSpeech(); // Platform-native TTS
builder.Services.AddOpenAiSpeech("key", speechToText: true, textToSpeech: false);
// OpenAI TTS only (use platform-native STT)
builder.Services.AddSpeechToText(); // Platform-native STT
builder.Services.AddOpenAiSpeech("key", speechToText: false, textToSpeech: true);