PSPDFSpeechController

Objective-C


@interface PSPDFSpeechController : NSObject

Swift

class SpeechController : NSObject

Controls text-to-speech features.

Note

This class can only be used from the main thread.

Voice availability depends on user settings, platform and os version. 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.

The Siri isn’t part of the voice selection list, Apple has “no plan to change” this. (rdar://42656565)

  • Speaks the given string. Will use the default system language, unless otherwise configured in options.

    Note

    Must be called on main thread. Delegate calls always happen on the main thread.

    Declaration

    Objective-C

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

    Swift

    func speakText(_ speechString: String, options: [SpeechController.Option : 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 (nonatomic, readonly) AVSpeechSynthesizer *_Nonnull speechSynthesizer;

    Swift

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

    Declaration

    Objective-C

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

    Swift

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

    Declaration

    Objective-C

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

    Swift

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

    Declaration

    Objective-C

    @property (nonatomic) float speakRate;

    Swift

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

    Declaration

    Objective-C

    @property (nonatomic) float pitchMultiplier;

    Swift

    var pitchMultiplier: Float { get set }