Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Sources/SwiftSpeech/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftSpeech/SpeechRecognizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down