SuperAPI AI 工具集

axiom-ios-ml-speech

通用与其它

查看项目

更新于 10-16 00:22

技能介绍

用途:在 Apple 平台实现语音转文字、实时转写或音频转写,尤其是 iOS 26+ 的长音频与远场对话场景。该技能主张优先使用 SpeechAnalyzer,它由系统管理本地模型,适合长音频、会议等远场说话人,且无需增大 App 体积。

主要能力:SpeechAnalyzer 为模块化分析会话,可加入转写模块,结果通过 AsyncSequence 异步流式返回。SpeechTranscriber 支持 transcriptionOptions、reportingOptions(如 .volatileResults 实时临时结果)和 attributeOptions(如 .audioTimeRange 获取时间信息),结果类型为 AttributedString。预设有 .offlineTranscription(文件转写)和 .progressiveLiveTranscription(实时转写)。另提供 DictationTranscriber,语言与 SFSpeechRecognizer 相同,但无需用户在设置中开启 Siri/听写。

使用方式:文件转写可用 SpeechAnalyzer(modules:) 加 analyzeSequence(from:),再 finalizeAndFinish(through:);实时转写需创建 SpeechTranscriber、获取 bestAvailableAudioFormat、用 AssetInventory.assetInstallationRequest 确保模型,通过 AsyncStream<AnalyzerInput> 输入音频,并处理 volatile 与 final 结果。接入麦克风时用 AVAudioEngine 采集并用 AVAudioConverter 转为分析器所需格式。

限制与注意:仅 iOS 26+、macOS Tahoe+ 等系统可用,watchOS 不支持 SpeechTranscriber。使用前应检查 supportedLocales,安装语言模型并处理下载进度;设备同时分配语言数量有限,可 deallocate。停止时必须调用 finalizeAndFinishThroughEndOfInput(),否则 volatile 结果会丢失;不转换音频格式可能静默失败。硬件要求因设备而异,需用 supportedLocales 确认。部分细节如 tvOS 状态、价格与更多平台支持暂未提供。