maui-speech-to-text

Add speech-to-text functionality to .NET MAUI apps using CommunityToolkit.Maui, covering speech recognition, microphone permissions, and hands-free text input, applicable across UI patterns (XAML/MVVM, C# Markup, MauiReactor).

Last repository push
GitHub Stars
181
Forks
21
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "maui-speech-to-text" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-5c4fb3163a77be544aa8bbf84a6b45ee18eb94e7e3daa8541b63ba98ef795c82. Verify the upstream source and version against https://github.com/davidortinau/maui-skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Add speech-to-text functionality to .NET MAUI apps using CommunityToolkit.Maui, covering speech recognition, microphone permissions, and hands-free text input, applicable across UI patterns (XAML/MVVM, C# Markup, MauiReactor).

0 Downloads

Introduction source: third_party · davidortinau · 0.0.1 Reference

SkillPi interpretation

Tasks
For full service implementation, types, and UI integration patterns, see `references/speech-to-text-api.md`.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: maui-speech-to-text
description: >
  Add speech-to-text voice input to .NET MAUI apps using CommunityToolkit.Maui.
  Covers speech recognition, microphone permissions, and hands-free text entry.
  Works with any UI pattern (XAML/MVVM, C# Markup, MauiReactor).
  USE FOR: "speech to text", "voice input", "speech recognition", "microphone input",
  "voice command", "dictation", "SpeechToText", "hands-free text", "transcribe speech".
  DO NOT USE FOR: text-to-speech output (different feature), media playback
  (use maui-media-picker), or general permissions (use maui-permissions).

Speech-to-Text — Gotchas & Best Practices

For full service implementation, types, and UI integration patterns, see references/speech-to-text-api.md.

Critical: Permission Handling

Always request permissions before starting speech recognition. Both microphone and speech permissions are required.

// ❌ Starting recognition without checking permissions
var result = await _speechService.StartListeningAsync();

// ✅ Always check permissions first
if (!await _speechService.RequestPermissionsAsync())
    return; // Gracefully handle denial
var result = await _speechService.StartListeningAsync(cancellationToken);

⚠️ iOS Requires Both Permission Descriptions

Missing either NSSpeechRecognitionUsageDescription or NSMicrophoneUsageDescription in Info.plist will cause a runtime crash — not a graceful failure.

⚠️ Android: Permission Re-prompt

On Android, if the user denies the RECORD_AUDIO permission twice, the OS stops showing the prompt. You must guide users to Settings manually.

Common Mistakes

❌ No Timeout — Indefinite Listening

Always set a timeout to prevent indefinite listening sessions that drain battery:

// ❌ No timeout — listens forever if no speech detected
await _speechToText.StartListenAsync(options, CancellationToken.None);

// ✅ Use a combined timeout + user cancellation token
using var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
using var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(
    userCancellationToken, timeoutCts.Token);
await _speechToText.StartListenAsync(options, combinedCts.Token);

❌ Not Unsubscribing Event Handlers

Leaking event subscriptions causes duplicate processing and memory leaks:

// ❌ Subscribe without unsubscribe
_speechToText.RecognitionResultUpdated += OnRecognitionResultUpdated;

// ✅ Always unsubscribe in finally block
try
{
    _speechToText.RecognitionResultUpdated += OnRecognitionResultUpdated;
    // ... listen ...
}
finally
{
    _speechToText.RecognitionResultUpdated -= OnRecognitionResultUpdated;
}

❌ Not Disposing CancellationTokenSource

// ❌ Leaked CTS
_currentCts = new CancellationTokenSource();

// ✅ Dispose in finally
try { /* ... */ }
finally
{
    _currentCts?.Dispose();
    _currentCts = null;
}

Platform Pitfalls

Platform Pitfall
iOS Missing either plist key → runtime crash
Android User denies permission twice → OS stops prompting; must redirect to Settings
All No timeout → battery drain from indefinite listening
All Calling StartListeningAsync while already listening → returns error, not exception

Architecture Tips

  1. Wrap ISpeechToText in a service — Don't use SpeechToText.Default directly in ViewModels. Wrap in ISpeechRecognitionService for testability and state management.

  2. Use partial results for UX — Subscribe to PartialResultReceived for live transcription feedback. Users expect to see words appear as they speak.

  3. Continuous listening = loop with delay — Loop StartListeningAsync with small delays (Task.Delay(100)) for conversation mode.

  4. Guard against double-start — Check state before starting:

    if (State == SpeechRecognitionState.Listening)
        return new SpeechRecognitionResultDto { Success = false, ErrorMessage = "Already listening" };
  5. Natural language output — CommunityToolkit.Maui returns normalized, punctuated text — not raw phonemes. No post-processing needed for basic use cases.

  6. UI-agnostic service — The ISpeechRecognitionService pattern works identically with XAML/MVVM, C# Markup, and MauiReactor. See references/speech-to-text-api.md for all three patterns.

Checklist

  • [ ] CommunityToolkit.Maui NuGet installed (look up current version)
  • [ ] UseMauiCommunityToolkit() called in MauiProgram.cs
  • [ ] ISpeechToText registered as singleton via DI
  • [ ] iOS: Both NSSpeechRecognitionUsageDescription and NSMicrophoneUsageDescription in Info.plist
  • [ ] Android: RECORD_AUDIO permission in AndroidManifest.xml
  • [ ] Permissions checked before every StartListeningAsync call
  • [ ] Timeout configured (recommend 60 seconds max)
  • [ ] Event handlers unsubscribed in finally blocks
  • [ ] CancellationTokenSource disposed after use

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • .NET MAUI 语音转文本集成指南,解决跨平台权限处理、事件泄漏、超时控制等实际开发痛点
  • 提供完整的架构建议和端到端实现清单,适用于 XAML/MVVM/C# Markup/MauiReactor 多种 UI 模式
Trigger Precision90/100

Highlights

  • 触发词覆盖全面(speech to text, voice input, dictation 等),边界清晰,明确排除不适用场景
Structure and Standards75/100

Areas to improve

  • 缺少显式阶段划分与完整端到端示例 Reported severity: Minor

    文档依赖外部 references/speech-to-text-api.md 提供完整实现,主文件内未提供自包含的完整示例流程

    Recommendation: 在主文件中补充一个最小可运行示例或明确标注阶段入口/出口条件

Highlights

  • 结构清晰,包含 Critical Pitfalls、Platform Differences、Architecture Tips 和 Checklist
Execution Reliability78/100

Areas to improve

  • 工具来源未明确标注官方链接 Reported severity: Minor

    提到 CommunityToolkit.Maui NuGet 但未提供官方包地址或文档链接

    Recommendation: 补充 CommunityToolkit.Maui 的官方 NuGet 链接和 GitHub 仓库地址

Highlights

  • 覆盖关键异常处理:权限预检、超时控制、事件取消订阅、CancellationTokenSource 释放
  • 针对不同平台(iOS/Android)的特殊陷阱提供具体解决方案
Evidence Verifiability (mean of the first four)82/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.