SpeechTilesAndamento Docs
Get started
Guide

Media Events

STMediaRunner performs many operations asynchronously. Rather than requiring separate callback models for playback, recording, recognition, permissions, device changes, and audio interruptions, SpeechTiles exposes a common typed media-event model.

Observing events

Create and retain an STEventsObserver, assign its delegate, and implement STMediaEventDelegate.

final class MediaController: STMediaEventDelegate {
    private let eventsObserver = STEventsObserver()

    init() {
        eventsObserver.delegate = self
    }

    func mediaEventReceived(_ event: STMediaEvent) {
        switch (event.function, event.type) {
        case (.speechRecognition, .srPartialHypothesis):
            if case .speechRecognition(let data) = event.data {
                print(data.hypothesis ?? "")
            }

        case (.audioRecording, .ended):
            if case .recording(let data) = event.data {
                print(data.stopReason as Any)
            }

        default:
            break
        }
    }
}

Retain the observer for as long as events need to be received. Its delegate is weak.

Event model

Each event has four layers:

  1. mediaJobID and mediaItemID correlate the event with application work.
  2. STMediaFunction identifies the media subsystem/activity.
  3. STMediaEventType identifies what happened.
  4. STMediaEventData carries the typed payload, when the event needs one.

This design lets the same event channel represent playback lifecycle, recording/VAD, speech recognition, application and system state, audio devices/routes, interruptions, permissions, media availability, and barge-in without falling back to untyped payload dictionaries.

See Also