Shiny.AiConversation
Shiny MAUI AiConversation - A centralized AI conversation service library for .NET MAUI apps
Install
| Product | Versions |
|---|---|
| .NET |
README
Shiny.AiConversation
A centralized AI service library for .NET MAUI apps that orchestrates chat, speech recognition, wake word detection, text-to-speech, and persistent message history into a single IAiConversationService interface.
Features
- Chat Integration β Send text or voice messages to any AI backend via Microsoft.Extensions.AI
- Wake Word Detection β Hands-free activation with continuous keyword listening
- Speech-to-Text / Text-to-Speech β Full voice loop powered by Shiny.Speech
- Acknowledgement Modes β None, AudioBlip (sound effects), LessWordy (concise TTS), or Full (complete TTS)
- Persistent Chat History β Pluggable
IMessageStorefor storing and querying past conversations - AI History Lookup Tool β Optional
AIToolthat lets the AI search past conversations on its own - State Management β Observable
AiState(Idle / Listening / Thinking / Responding) with events - Sound Effects β Configurable sound stream factories for each state transition
Installation
dotnet add package Shiny.AiConversation
Quick Start
1. Register the service
using Shiny.AiConversation;
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts => { ... });
builder.Services.AddShinyAiConversation(opts =>
{
// Required β your IChatClientProvider implementation
opts.SetChatClientProvider<MyChatClientProvider>();
// Optional β enable persistent history + AI lookup tool
opts.SetMessageStore<MyMessageStore>(addAiLookupTool: true);
});
var app = builder.Build();
// Configure after build
var ai = app.Services.GetRequiredService<IAiConversationService>();
ai.SystemPrompts.Add("You are a helpful assistant.");
ai.SoundResolver = name => FileSystem.OpenAppPackageFileAsync(name);
ai.OkSound = "ok.mp3";
ai.ThinkSound = "think.mp3";
ai.RespondingSound = "responding.mp3";
ai.ErrorSound = "error.mp3";
ai.CancelSound = "cancel.mp3";
return app;
2. Implement IChatClientProvider
This is how the library obtains a chat client. You control authentication, token management, and which AI backend to use.
using Microsoft.Extensions.AI;
using Shiny.AiConversation;
public class MyChatClientProvider : IChatClientProvider
{
public async Task<IChatClient> GetChatClient(CancellationToken cancelToken = default)
{
// Build and return any IChatClient β OpenAI, Azure, GitHub Copilot, etc.
var client = new OpenAIClient("your-api-key");
return client.GetChatClient("gpt-4o").AsIChatClient();
}
}
3. Implement IMessageStore (optional)
Provide persistent storage for chat history. Without this, GetChatHistory and ClearChatHistory will throw.
using Shiny.AiConversation;
public class MyMessageStore : IMessageStore
{
public Task Store(AiChatMessage chatMessage, CancellationToken cancellationToken)
{
// Persist the message
}
public Task Clear(DateTimeOffset? beforeDate = null)
{
// Clear all or messages before the given date
}
public Task<IReadOnlyList<AiChatMessage>> Query(
string? messageContains = null,
DateTimeOffset? fromDate = null,
DateTimeOffset? toDate = null,
int? limit = null,
CancellationToken cancellationToken = default)
{
// Query with optional filters, return ordered by timestamp
}
}
4. Use the service
public class ChatViewModel(IAiConversationService aiService) : ObservableObject
{
public async Task SendMessage(string text)
{
await aiService.TalkTo(text, CancellationToken.None);
}
public async Task UseMicrophone()
{
await aiService.ListenAndTalk(CancellationToken.None);
}
public async Task StartWakeWord()
{
await aiService.StartWakeWord("Hey Assistant");
}
}
API Overview
IAiConversationService
| Member | Description |
|---|---|
TalkTo(string, CancellationToken) |
Send a text message to the AI |
ListenAndTalk(CancellationToken) |
Capture speech via microphone and send to AI |
StartWakeWord(string) |
Begin continuous wake word detection |
StopWakeWord() |
Stop wake word detection |
GetChatHistory(...) |
Query persisted chat history with optional filters |
ClearChatHistory(...) |
Clear persisted history (all or before a date) |
ClearCurrentChat() |
Clear in-memory session messages |
Status |
Current AiState (Idle / Listening / Thinking / Responding) |
Acknowledgement |
Get/set the response delivery mode |
SystemPrompts |
System prompts prepended to every request |
StateChanged |
Event fired on any state change |
AiResponded |
Event fired with the AI's response text, timestamp, and whether it was read aloud |
Acknowledgement Modes
| Mode | Behavior |
|---|---|
None |
No audio feedback or text-to-speech |
AudioBlip |
Short sound effects at state transitions |
LessWordy |
Text-to-speech with a "be concise" system prompt |
Full |
Text-to-speech with full unmodified responses |
ChatLookupAITool
When SetMessageStore<T>(addAiLookupTool: true) is used, the library registers an AITool named lookup_chat_history. This allows the AI to autonomously search past conversations when the user asks about previous discussions β no extra code required.
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β IAiConversationService β
β (orchestrates chat, speech, sounds, history) β
ββββββββββββ¬βββββββββββββββ¬ββββββββββββββββββββββββ€
β β β β
β IChatClientProvider β IMessageStore β
β (auth + AI backend) β (persistence) β
β β β β β
β IChatClient ISpeechToText β ChatLookupAITool
β (M.E.AI) ITextToSpeech β (optional AITool)
β (Shiny.Speech) β β
β β β β
β IAudioPlayer β β
β (Shiny.Speech) β β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
Dependencies
| Package | Purpose |
|---|---|
| Microsoft.Extensions.AI | IChatClient abstraction |
| Shiny.Speech | Speech-to-text, text-to-speech, and audio playback |
License
MIT
Changes from Previous Version
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.