English | 日本語
Let people speak instead of type in an iOS or macOS app, with permission refusals, streaming partial text and start/stop state already handled.
- The engine is a seam, not a commitment — Apple's recogniser is the default, not the design. Anything conforming to
SpeechRecognizerdrops in, which is also what makes the state machine testable without a microphone. - Text as it is spoken — partial results stream in and are published as a plain observable string, so a view binds to a property instead of managing a stream.
- Refused permissions handled — the one path most voice features get wrong. A denial is not retryable in-app, and the supplied button says so and routes the user to Settings.
- UI is optional —
VoiceInputcarries the recogniser and session;VoiceInputUIcarries the SwiftUI controls. Depend on the first alone and SwiftUI never enters the build.
The host app must declare both usage descriptions in its Info.plist:
NSMicrophoneUsageDescription— why the app records audioNSSpeechRecognitionUsageDescription— why that audio is transcribed
Missing either one terminates the app the moment that permission is requested, so the symptom is a crash on first tap rather than a denied permission.
import VoiceInput
import VoiceInputUI
struct DictationField: View {
@State private var session = VoiceInputSession()
@State private var text = ""
var body: some View {
HStack {
TextField("Type here…", text: $text)
VoiceInputButton(session: session)
}
.voiceInputOverlay(session: session) { transcript in
text = transcript
}
}
}API reference and guides — including Getting Started, substituting a recognition engine, and what separates a partial result from a final one.
| iOS | macOS | Swift |
|---|---|---|
| 17.0+ | 14.0+ | 6.2+ |
dependencies: [
.package(url: "https://github.com/no-problem-dev/swift-voice-input.git", from: "3.0.0"),
]Then take one or both products — VoiceInput for the session and recogniser,
VoiceInputUI for the SwiftUI controls:
.product(name: "VoiceInput", package: "swift-voice-input"),
.product(name: "VoiceInputUI", package: "swift-voice-input"),See CONTRIBUTING.md.
MIT — see LICENSE.