Understand the SwiftSpeech Composable Structure
masterSwiftSpeech is built using a three-part composable structure that separates UI, interaction logic, and data handling:
- The View Component: A
Viewresponsible solely for the UI (e.g.,SwiftSpeech.RecordButton()). - The Functional Component: Handles user interaction and provides speech recognition functionality. It is applied as a modifier to the View Component. Examples include:
.swiftSpeechRecordOnHold(sessionConfiguration:animation:distanceToCancel:): Enables recording while holding and allows canceling by swiping up..swiftSpeechToggleRecordingOnTap(sessionConfiguration:animation:): Toggles recording on tap.
- SwiftSpeech Modifier(s): Applied to the functional component to receive and manipulate recognition results (e.g.,
.onRecognizeLatest(...)).
Note on Chaining: Chaining multiple or identical modifiers does not override behavior; all actions execute in order, starting from the modifier closest to the Functional Component.
SwiftSpeech.RecordButton() // 1. The View Component
.swiftSpeechRecordOnHold(sessionConfiguration:animation:distanceToCancel:) // 2. The Functional Component
.onRecognizeLatest(update: $text) // 3. SwiftSpeech Modifier(s)