TranscriptLine
A single line of transcription representing a phrase or segment of speech.
public struct TranscriptLine
Properties
UTF-8 encoded transcription text
Time offset from the start of the audio in seconds
Duration of the segment in seconds
Stable identifier for the line (unique within a session)
Whether the line is complete. When true, the text will not change anymore.
Whether the line has been updated since the previous call (streaming only)
Whether the line was newly added since the previous call (streaming only)
Whether the text has changed since the previous call (streaming only)
Whether a speaker ID has been calculated for the line
The speaker ID for the line (only valid if hasSpeakerId is true)
The order the speaker appeared in the current transcript (0-based)
Audio data for this line if available (16KHz float PCM, -1.0 to 1.0)
Example:
let line: TranscriptLine = // ... from event
print("[\(line.startTime)s] \(line.text)")
print("Duration: \(line.duration)s")
print("Complete: \(line.isComplete)")
if line.hasSpeakerId {
print("Speaker \(line.speakerIndex + 1)")
}
Transcript
A complete transcript containing multiple lines.
Properties
All lines of the transcript in chronological order
Example:
let transcript = try transcriber.transcribeWithoutStreaming(
audioData: audioData,
sampleRate: 16000
)
for line in transcript.lines {
print("[\(line.startTime)s] \(line.text)")
}
let fullText = transcript.lines.map { $0.text }.joined(separator: " ")
print("Full transcript: \(fullText)")
TranscriptEvent (Protocol)
Base protocol for all transcript events.
public protocol TranscriptEvent
Properties
The transcript line associated with this event
The handle of the stream that emitted this event
LineStarted
Event emitted when a new transcription line starts.
public struct LineStarted: TranscriptEvent
Example:
func onLineStarted(_ event: LineStarted) {
print("New line started: \(event.line.text)")
}
LineUpdated
Event emitted when an existing transcription line is updated.
public struct LineUpdated: TranscriptEvent
Example:
func onLineUpdated(_ event: LineUpdated) {
print("Line updated: \(event.line.text)")
}
LineTextChanged
Event emitted when the text of a transcription line changes.
public struct LineTextChanged: TranscriptEvent
Example:
func onLineTextChanged(_ event: LineTextChanged) {
// Update UI with new text
updateTranscriptDisplay(event.line.text)
}
LineCompleted
Event emitted when a transcription line is completed.
public struct LineCompleted: TranscriptEvent
Example:
func onLineCompleted(_ event: LineCompleted) {
print("Final text: \(event.line.text)")
// Save to database, process final result, etc.
}
TranscriptError
Event emitted when an error occurs.
public struct TranscriptError: TranscriptEvent
Properties
Example:
func onError(_ event: TranscriptError) {
print("Error: \(event.error.localizedDescription)")
}
TranscriptEventListener (Protocol)
Protocol for objects that listen to transcript events.
public protocol TranscriptEventListener: AnyObject
Methods
All methods have default no-op implementations, so you only need to override the ones you care about.
func onLineStarted(_ event: LineStarted)
func onLineUpdated(_ event: LineUpdated)
func onLineTextChanged(_ event: LineTextChanged)
func onLineCompleted(_ event: LineCompleted)
func onError(_ event: TranscriptError)
Example:
class MyListener: TranscriptEventListener {
// Only implement the events you care about
func onLineTextChanged(_ event: LineTextChanged) {
print(event.line.text)
}
func onLineCompleted(_ event: LineCompleted) {
print("Final: \(event.line.text)")
}
}
ModelArch
Model architecture types supported by Moonshine Voice.
public enum ModelArch: UInt32
Cases
26 million parameters, smallest model
58 million parameters, good balance of accuracy and speed
34 million parameters, streaming variant of tiny
58 million parameters, streaming variant of base
123 million parameters, higher accuracy streaming model
245 million parameters, highest accuracy streaming model
Example:
let transcriber = try Transcriber(
modelPath: modelPath,
modelArch: .mediumStreaming
)
Stream
A stream for real-time transcription with event-based updates.
Methods
start()
Start the stream.
public func start() throws
stop()
Stop the stream and process any remaining audio.
public func stop() throws
addAudio(_:sampleRate:)
Add audio data to the stream.
public func addAudio(_ audioData: [Float], sampleRate: Int32 = 16000) throws
updateTranscription(flags:)
Manually update the transcription from the stream.
public func updateTranscription(flags: UInt32 = 0) throws -> Transcript
addListener(_:)
Add an event listener to the stream.
public func addListener(_ listener: @escaping (TranscriptEvent) throws -> Void)
public func addListener(_ listener: TranscriptEventListener)
removeListener(_:)
Remove an event listener from the stream.
public func removeListener(_ listener: @escaping (TranscriptEvent) throws -> Void)
public func removeListener(_ listener: TranscriptEventListener)
removeAllListeners()
Remove all event listeners.
public func removeAllListeners()
close()
Close the stream and free its resources.
Example:
let stream = try transcriber.createStream(updateInterval: 0.3)
stream.addListener { event in
if let completed = event as? LineCompleted {
print(completed.line.text)
}
}
try stream.start()
try stream.addAudio(audioData, sampleRate: 16000)
try stream.stop()
stream.close()