OSSSpeech

@available(*, deprecated, message: "Use the instance-based OSSSpeechEngine async API.")
public class OSSSpeech : NSObject, @unchecked Sendable
extension OSSSpeech: SFSpeechRecognitionTaskDelegate, SFSpeechRecognizerDelegate

Speech is the primary interface. To use, set the voice and then call .speak(string: "your string")

Variables

  • Delegate allows for the recieving of spoken events.

    Declaration

    Swift

    public weak var delegate: OSSSpeechDelegate?
  • An object that allows overriding the default AVVoice options.

    Declaration

    Swift

    public var voice: OSSVoice?
  • Speech recognition variable to determine if recognition should use on device capabilities if available

    Not all devices support on device speech recognition and only devices operating with iOS 13 or higher support it.

    On device recognition offers many benefits such as working without network connectivity, no data costs and longer recording-to-transcription.

    On device recognition comes at a cost of accurate transcription though; speech recognition is less accurate with on device recognition.

    Declaration

    Swift

    public var shouldUseOnDeviceRecognition: Bool
  • The task type by default is undefined. Changing the task type will change how speech recognition performs.

    Declaration

    Swift

    public var recognitionTaskType: OSSSpeechRecognitionTaskType
  • The object used to enable translation of strings to synthsized voice.

    Declaration

    Swift

    public var utterance: OSSUtterance?
  • Audio Session can be overriden should you choose to.

    Declaration

    Swift

    public var audioSession: AVAudioSession { get set }
  • srp

    This property handles permission authorization. This property is intentionally named vaguely to prevent accidental overriding.

    Declaration

    Swift

    @available(*, deprecated, message: "Use dependency injection with OSSSpeechEngine tests.")
    public var srp: SFSpeechRecognizer.Type

Lifecycle

  • Allow injection of the AVSpeechSynthesizer so that caller can be AVSpeechSynthesizerDelegate func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance) { func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) {

    Declaration

    Swift

    public init(speechSynthesizer: AVSpeechSynthesizer = AVSpeechSynthesizer())
  • A singleton object to ensure conformity accross the application it is used in.

    Declaration

    Swift

    @available(*, deprecated, message: "Create an OSSSpeechEngine instance instead.")
    public class var shared: OSSSpeech { get }

Public Methods

  • Pass in a string to speak. This will set the speechString on the utterance.

    Declaration

    Swift

    public func speakText(_ text: String? = nil)

    Parameters

    text

    An String object.

  • Pass in an attributed string to speak. This will set the attributed string on the utterance.

    Declaration

    Swift

    public func speakAttributedText(attributedText: NSAttributedString)

    Parameters

    attributedText

    An NSAttributedString object.

  • Pause speaking text

    Will check if the current speech synthesizer session is speaking before attempting to pause.

    Declaration

    Swift

    public func pauseSpeaking()
  • Continue speaking text

    Will check if the current speech synthesizer session is paused before attempting to continue speaking.

    Declaration

    Swift

    public func continueSpeaking()
  • Force the ending of speaking.

    Does not remove or reset the utterance or voice - only stops the current speaking if it’s active. Also checks to see if the current synthesizer session is paused.

    Declaration

    Swift

    public func stopSpeaking()

Public Voice Recording Methods

  • Record and recognise speech

    This method will check to see if user is authorised to record. If they are, the recording will proceed.

    Upon checking the authorisation and being registered successful, a check to determine if a recording session is active will be made and any active session will be cancelled.

    Declaration

    Swift

    public func recordVoice(requestMicPermission requested: Bool = true)
  • End recording of speech session if one exists.

    Declaration

    Swift

    public func endVoiceRecording()

SFSpeechRecognitionTaskDelegate Methods

  • Docs available by Google searching for SFSpeechRecognitionTaskDelegate

    Declaration

    Swift

    public func speechRecognitionTask(_ task: SFSpeechRecognitionTask, didFinishSuccessfully successfully: Bool)
  • Docs available by Google searching for SFSpeechRecognitionTaskDelegate

    Declaration

    Swift

    public func speechRecognitionTask(_ task: SFSpeechRecognitionTask, didHypothesizeTranscription transcription: SFTranscription)
  • Docs available by Google searching for SFSpeechRecognitionTaskDelegate

    Declaration

    Swift

    public func speechRecognitionTask(_ task: SFSpeechRecognitionTask, didFinishRecognition recognitionResult: SFSpeechRecognitionResult)
  • Called when the recognizer detects speech in the audio stream.

    Declaration

    Swift

    public func speechRecognitionDidDetectSpeech(_ task: SFSpeechRecognitionTask)
  • Called when the recognizer has finished reading audio from the request.

    Declaration

    Swift

    public func speechRecognitionTaskFinishedReadingAudio(_ task: SFSpeechRecognitionTask)

SFSpeechRecognizerDelegate Methods

  • Docs available by Google searching for SFSpeechRecognizerDelegate

    Declaration

    Swift

    public func speechRecognizer(_ speechRecognizer: SFSpeechRecognizer, availabilityDidChange available: Bool)