Bringing advanced speech-to-text capabilities to your app
At a glance
| Item | Summary |
|---|---|
| Purpose | Learn how to incorporate live speech-to-text transcription into your app with SpeechAnalyzer. |
| App architecture | A Swift sample with the source-visible chain SwiftTranscriptionSampleAppApp → ContentView → BufferConverter → Speech APIs. |
| Main patterns | Binding-based state propagation |
| Project style | 8 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
├── SwiftTranscriptionSampleApp/
│ ├── Helpers/
│ │ ├── SwiftTranscriptionSampleAppApp.swift
│ │ ├── Helpers.swift
│ │ └── BufferConversion.swift
│ ├── Models/
│ │ └── StoryModel.swift
│ ├── Recording and Transcription/
│ │ ├── Recorder.swift
│ │ └── Transcription.swift
│ └── Views/
│ ├── ContentView.swift
│ └── TranscriptView.swift
├── Configuration/
│ └── SampleCode.xcconfig
└── SwiftTranscriptionSampleApp.xcodeproj/
├── .xcodesamplecode.plist
└── project.pbxproj
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 3 project/configuration file(s) and 13 source declaration(s).
Overall architecture
flowchart LR
N1["SwiftTranscriptionSampleAppApp"]
N2["ContentView"]
N3["BufferConverter"]
N4["Speech APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
SwiftTranscriptionSampleApp/Helpers/SwiftTranscriptionSampleAppApp.swift:11 — architecture anchor
@main
struct SwiftTranscriptionSampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Speech.
Ownership and state
classDiagram
Story *-- UUID : id
Story *-- String : title
Story o-- AttributedString : text
Story *-- URL : url
Ownership evidence
SwiftTranscriptionSampleApp/Models/StoryModel.swift:16 — stored dependency or nearest verified ownership anchor
@Observable
class Story: Identifiable {
// ...
let id: UUID
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
Story |
UUID (id) |
owns value state | Initialized by the owner; the binding is immutable |
Story |
String (title) |
owns value state | App/module collaborators |
Story |
AttributedString (text) |
stores or receives | App/module collaborators |
Story |
URL (url) |
owns value state | App/module collaborators |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Class and protocol design
SwiftTranscriptionSampleApp/Helpers/SwiftTranscriptionSampleAppApp.swift:12 — representative type boundary
struct SwiftTranscriptionSampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
SwiftTranscriptionSampleApp |
Application entry and top-level composition | App |
Recorder |
Owns capture or recording work | Concrete collaborators/imported frameworks |
ContentView |
User-interface presentation and input forwarding | View |
TranscriptView |
User-interface presentation and input forwarding | View |
BufferConverter |
Transforms between feature representations | Concrete collaborators/imported frameworks |
Story |
Owns feature behavior and collaborator lifecycle | Identifiable |
TranscriptionState |
Represents mutable feature state | Concrete collaborators/imported frameworks |
TranscriptionError |
Represents feature failure conditions | Error |
RecordingState |
Represents mutable feature state | Equatable |
PlaybackState |
Represents mutable feature state | Equatable |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
converter (SwiftTranscriptionSampleApp/Helpers/BufferConversion.swift:18) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
outputContinuation (SwiftTranscriptionSampleApp/Recording and Transcription/Recorder.swift:13) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
audioEngine (SwiftTranscriptionSampleApp/Recording and Transcription/Recorder.swift:14) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
transcriber (SwiftTranscriptionSampleApp/Recording and Transcription/Recorder.swift:15) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
SwiftTranscriptionSampleApp/Helpers/BufferConversion.swift:18 — representative boundary
class BufferConverter {
// ...
private var converter: AVAudioConverter?
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | SwiftTranscriptionSampleApp |
The source’s App suffix makes this role explicit. |
| Transforms between feature representations | BufferConverter |
The source’s Converter suffix makes this role explicit. |
| Owns capture or recording work | Recorder |
The source’s Recorder suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, TranscriptView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Binding-based state propagation | SwiftTranscriptionSampleApp/Views/TranscriptView.swift:14 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Naming conventions
- Types: App: SwiftTranscriptionSampleApp; Converter: BufferConverter; Recorder: Recorder; View: ContentView, TranscriptView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
suggestedTitle,blank,storyBrokenUpByLines,hash,isAuthorized,writeBufferToDisk,handlePlayback,handleRecordingButtonTap. - Files:
SwiftTranscriptionSampleApp/Recording and Transcription/Recorder.swift,SwiftTranscriptionSampleApp/Views/ContentView.swift,SwiftTranscriptionSampleApp/Views/TranscriptView.swift.
Architecture takeaways
SwiftTranscriptionSampleAppAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, AVFoundation, Speech, SwiftData through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
SwiftTranscriptionSampleApp/Helpers/SwiftTranscriptionSampleAppApp.swift |
SwiftTranscriptionSampleApp |
SwiftTranscriptionSampleApp/Models/StoryModel.swift |
Story |
SwiftTranscriptionSampleApp/Helpers/Helpers.swift |
TranscriptionState, TranscriptionError, RecordingState, PlaybackState, AudioData |
SwiftTranscriptionSampleApp/Recording and Transcription/Recorder.swift |
Recorder |
SwiftTranscriptionSampleApp/Views/ContentView.swift |
ContentView |
SwiftTranscriptionSampleApp/Views/TranscriptView.swift |
TranscriptView |
SwiftTranscriptionSampleApp/Helpers/BufferConversion.swift |
BufferConverter, Error |
SwiftTranscriptionSampleApp/Recording and Transcription/Transcription.swift |
SpokenWordTranscriber |