用途:使用 Apple Speech 框架把实时或预录音频转写为文本,涵盖 iOS 26+ 的 SpeechAnalyzer/SpeechTranscriber 与 iOS 10+ 的 SFSpeechRecognizer 回退方案。范围限于语音识别、语音授权、麦克风采集与结果处理;文本分析、转写后的语言识别、情感、嵌入与翻译交给 natural-language,音频播放 UI 交给 avkit,转写文本的摘要或生成交给 apple-on-device-ai。
主要能力:iOS 26+ 可用 SpeechTranscriber(通用端上模型)、DictationTranscriber(不可用时的听写兼容支持)、SpeechDetector(配合转写器做语音活动检测);创建会话前检查 SpeechTranscriber.isAvailable、supportedLocale(equivalentTo:)、installedLocales/supportedLocales,选择 .transcription、.progressiveTranscription、.timeIndexedProgressiveTranscription 预设,用 AssetInventory.assetInstallationRequest 安装资源,实时缓冲需转换为 SpeechAnalyzer.bestAvailableAudioFormat(compatibleWith:) 后再产出 AnalyzerInput,并在独立任务中消费 AsyncSequence,最后用 finalizeAndFinish(through:)、finalizeAndFinishThroughEndOfInput() 或 cancelAndFinishNow() 显式结束。SFSpeechRecognizer 支持指定 locale、isAvailable 检查与 SFSpeechRecognizerDelegate 的 availabilityDidChange 监听。
使用方式:实时转写需在 Info.plist 添加 NSSpeechRecognitionUsageDescription 与 NSMicrophoneUsageDescription,先请求语音与麦克风权限;用 AVAudioEngine 采集,缓冲追加到 SFSpeechAudioBufferRecognitionRequest,结果通过 recognitionTask 回调返回。文件识别用 SFSpeechURLRecognitionRequest。可设置 shouldReportPartialResults、addsPunctuation(iOS 16+)、contextualStrings 提升领域词识别。端上识别需检查 supportsOnDeviceRecognition 后再设 requiresOnDeviceRecognition。
限制:SFSpeechRecognizer 有约一分钟任务限制及服务限制,长录音在 iOS 26+ 优先用 SpeechAnalyzer,否则需分段或重启并保留已确认转写;不要使用未文档化的 offlineTranscription 预设;结束 AsyncStream 输入不等于结束分析器会话;易变结果需被最终结果替换而非追加。资料未提供收费、价格与平台支持范围等信息。