OSSSpeechEngine
@MainActor
public final class OSSSpeechEngine : NSObject
extension OSSSpeechEngine: AVSpeechSynthesizerDelegate, SFSpeechRecognizerDelegate
Instance-based, main-actor-isolated speech synthesis and recognition engine.
-
Current high-level activity of the speech engine.
See moreDeclaration
Swift
public enum State : Equatable -
Current high-level activity of the engine.
Declaration
Swift
@MainActor public private(set) var state: State { get } -
Whether recognition should require on-device processing when supported.
Declaration
Swift
@MainActor public var usesOnDeviceRecognition: Bool -
Task hint passed to the underlying speech recognizer.
Declaration
Swift
@MainActor public var recognitionTaskHint: SFSpeechRecognitionTaskHint -
Creates a speech engine with its own synthesizer, audio engine, and audio session.
Declaration
Swift
@MainActor public override init() -
Locales that the platform reports as available for speech recognition.
Declaration
Swift
@MainActor public static var supportedRecognitionLocales: Set<Locale> { get } -
requestSpeechAuthorization()AsynchronousRequests speech recognition authorization and maps the native status.
Declaration
Swift
@MainActor public func requestSpeechAuthorization() async -> OSSSpeechKitAuthorizationStatus -
requestMicrophoneAuthorization()AsynchronousRequests microphone recording authorization.
Declaration
Swift
@MainActor public func requestMicrophoneAuthorization() async -> Bool -
speak(_:Asynchronousvoice: configuration: ) Speaks plain text using a resolved AVFoundation voice.
Declaration
Swift
@MainActor public func speak( _ text: String, voice: OSSVoiceConfiguration, configuration: OSSUtteranceConfiguration = .init() ) async throws -
speak(_:Asynchronousvoice: configuration: ) Speaks attributed text using a resolved AVFoundation voice.
Declaration
Swift
@MainActor public func speak( _ attributedText: NSAttributedString, voice: OSSVoiceConfiguration, configuration: OSSUtteranceConfiguration = .init() ) async throws -
Pauses the current utterance immediately when the engine is speaking.
Declaration
Swift
@MainActor public func pauseSpeaking() -
Resumes a paused utterance.
Declaration
Swift
@MainActor public func continueSpeaking() -
Stops the current utterance and finishes the synthesis operation.
Declaration
Swift
@MainActor public func stopSpeaking() -
recognitionEvents(locale:AsynchronousrequestAuthorization: ) Starts recognition and returns a stream that owns the recording session. Cancelling iteration tears down the audio tap and recognition task.
Declaration
Swift
@MainActor public func recognitionEvents( locale: Locale, requestAuthorization: Bool = true ) async throws -> AsyncThrowingStream<OSSSpeechRecognitionEvent, Error> -
Cancels the active recognition session and tears down audio recording.
Declaration
Swift
@MainActor public func cancelRecognition() -
Completes the awaiting synthesis operation when AVFoundation finishes speaking.
Declaration
Swift
nonisolated public func speechSynthesizer( _ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance ) -
Completes the awaiting synthesis operation with cancellation when speech is cancelled.
Declaration
Swift
nonisolated public func speechSynthesizer( _ synthesizer: AVSpeechSynthesizer, didCancel utterance: AVSpeechUtterance ) -
Emits recognizer availability changes to the active recognition stream.
Declaration
Swift
nonisolated public func speechRecognizer( _ speechRecognizer: SFSpeechRecognizer, availabilityDidChange available: Bool )
View on GitHub
OSSSpeechEngine Class Reference