PSPDFSpeechController


@interface PSPDFSpeechController : NSObject

Controls text-to-speech features.

Note

This class can only be used from the main thread.

Voice availability depends on user settings. High-quality voices might need to be manually downloaded https://support.apple.com/en-us/HT203077

Voice selection uses [AVSpeechSynthesisVoice voiceWithLanguage:]. This will return enhanced quality voice if available, default quality otherwise.

As of iOS 12b4, Siri isn’t part of the voice selection list. rdar://42656565. (Has been closed as no plan to change)

  • Speak string. Setting language to nil will use the default language set here.

    Declaration

    Objective-C

    - (void)speakText:(nonnull NSString *)speechString
              options:(nullable NSDictionary<NSString *, id> *)options
             delegate:(nullable id<AVSpeechSynthesizerDelegate>)delegate;

    Swift

    @IBAction func speakText(_ speechString: String, options: [String : Any]? = nil, delegate: AVSpeechSynthesizerDelegate?)
  • If this delegate is set, stop current text.

    Declaration

    Objective-C

    - (BOOL)stopSpeakingForDelegate:
        (nullable id<AVSpeechSynthesizerDelegate>)delegate;

    Swift

    func stopSpeaking(for delegate: AVSpeechSynthesizerDelegate?) -> Bool
  • The internally used speech synthesizer.

    Declaration

    Objective-C

    @property (readonly, nonatomic) AVSpeechSynthesizer *_Nonnull speechSynthesizer;

    Swift

    var speechSynthesizer: AVSpeechSynthesizer { get }
  • Speech language. Defaults to PSPDFSpeechSynthesizerAutoDetectLanguage.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic) NSString *_Nonnull selectedLanguage;

    Swift

    var selectedLanguage: String { get set }
  • Available language codes, use for selectedLanguage.

    Declaration

    Objective-C

    @property (readonly, copy, nonatomic)
        NSArray<NSString *> *_Nonnull languageCodes;

    Swift

    var languageCodes: [String] { get }
  • Speech rate. Defaults to AVSpeechUtteranceDefaultSpeechRate.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) float speakRate;

    Swift

    var speakRate: Float { get set }
  • Speech pitch. Defaults to 1.0f.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) float pitchMultiplier;

    Swift

    var pitchMultiplier: Float { get set }