maui-speech-to-text

使用 CommunityToolkit.Maui 在 .NET MAUI 应用中加入语音转文本功能,涵盖语音识别、麦克风权限与无手动文本输入的实现,适用于各种 UI 模式(XAML/MVVM、C# Markup、MauiReactor)。

仓库最近推送
GitHub Stars
181
Forks
21
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "maui-speech-to-text":https://skillpi.com/zh/skills/deepskill-5c4fb3163a77be544aa8bbf84a6b45ee18eb94e7e3daa8541b63ba98ef795c82。安装前核对上游来源和版本:https://github.com/davidortinau/maui-skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

使用 CommunityToolkit.Maui 在 .NET MAUI 应用中加入语音转文本功能,涵盖语音识别、麦克风权限与无手动文本输入的实现,适用于各种 UI 模式(XAML/MVVM、C# Markup、MauiReactor)。

0 下载

介绍来源: third_party · davidortinau · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
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

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

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

亮点

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

待提升项

  • 缺少显式阶段划分与完整端到端示例 原报告严重程度:轻微

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

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

亮点

  • 结构清晰,包含 Critical Pitfalls、Platform Differences、Architecture Tips 和 Checklist
执行可靠78/100

待提升项

  • 工具来源未明确标注官方链接 原报告严重程度:轻微

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

    改进建议:补充 CommunityToolkit.Maui 的官方 NuGet 链接和 GitHub 仓库地址

亮点

  • 覆盖关键异常处理:权限预检、超时控制、事件取消订阅、CancellationTokenSource 释放
  • 针对不同平台(iOS/Android)的特殊陷阱提供具体解决方案
证据可验 (前四项均值)82/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

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

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。