diff --git a/Sources/SwiftSpeech/Session.swift b/Sources/SwiftSpeech/Session.swift index 865eec9..c8334b5 100644 --- a/Sources/SwiftSpeech/Session.swift +++ b/Sources/SwiftSpeech/Session.swift @@ -113,6 +113,13 @@ public extension SwiftSpeech.Session { */ public var interactionIdentifier: String? = nil + /** + Set this property to true for the speech framework to automatically include punctuation in the recognition results. Punctuation includes a period or question mark at the end of a sentence, and a comma within a sentence. + + Only avaliable on iOS 16.0+, visionOS 1.0+ + */ + public var addsPunctuation:Bool = true + /** A configuration for configuring/activating/deactivating your app's `AVAudioSession` at the appropriate time. The default value is `.recordOnly`, which activate/deactivate a **record only** audio session when a recording session starts/stops. @@ -138,6 +145,28 @@ public extension SwiftSpeech.Session { self.interactionIdentifier = interactionIdentifier self.audioSessionConfiguration = audioSessionConfiguration } + + + @available(iOS 16,visionOS 1.0, *) + public init( + locale: Locale = .current, + taskHint: SFSpeechRecognitionTaskHint = .unspecified, + shouldReportPartialResults: Bool = true, + requiresOnDeviceRecognition: Bool = false, + contextualStrings: [String] = [], + interactionIdentifier: String? = nil, + addsPunctuation: Bool = true, + audioSessionConfiguration: AudioSessionConfiguration = .recordOnly + ) { + self.locale = locale + self.taskHint = taskHint + self.shouldReportPartialResults = shouldReportPartialResults + self.requiresOnDeviceRecognition = requiresOnDeviceRecognition + self.contextualStrings = contextualStrings + self.interactionIdentifier = interactionIdentifier + self.addsPunctuation = addsPunctuation + self.audioSessionConfiguration = audioSessionConfiguration + } } } diff --git a/Sources/SwiftSpeech/SpeechRecognizer.swift b/Sources/SwiftSpeech/SpeechRecognizer.swift index 05fdd56..888cc99 100644 --- a/Sources/SwiftSpeech/SpeechRecognizer.swift +++ b/Sources/SwiftSpeech/SpeechRecognizer.swift @@ -65,6 +65,9 @@ public class SpeechRecognizer { recognitionRequest.taskHint = sessionConfiguration.taskHint recognitionRequest.contextualStrings = sessionConfiguration.contextualStrings recognitionRequest.interactionIdentifier = sessionConfiguration.interactionIdentifier + if #available(iOS 16,visionOS 1.0, *) { + recognitionRequest.addsPunctuation = sessionConfiguration.addsPunctuation + } // Create a recognition task for the speech recognition session. // Keep a reference to the task so that it can be cancelled.