SystemTextToSpeechEngine
public class SystemTextToSpeechEngine : TextToSpeechEngine
Important
This is a Public Preview API. It may be changed or removed at any time.-
Creates an instance of
SystemTextToSpeechEngine
. The initializer will throw an error if voices are not downloaded to the iOS device. You could use the following code to check if the specific voice for the given language is present on your device or not.import AVFoundation let languageCode = "en-US" // you can change this to the desired language code if SystemTextToSpeechEngine.isVoiceAvailable(for: languageCode) { // Creates an instance of ``SystemTextToSpeechEngine`` } else { // Guide the user to download the voice or use a fallback }
For more details about the
AVSpeechSynthesisVoice
read the Apple documentation: https://developer.apple.com/documentation/avfaudio/avspeechsynthesisvoiceThrows
TextToSpeechEngineError.unavailableLocaleInVoices
if there is no speech voice for the givenlanguage
.Declaration
Swift
public init(language: Locale = Locale(identifier: "en_US"), gender: AVSpeechSynthesisVoiceGender? = nil) throws
Parameters
language
Identifies in which language the voice instructions will be spoken. The
Locale(identifier: "en_US")
is used by default.gender
The gender for a voice. If the
gender
isnil
then the gender voice will be used that exists for the givenlanguage
on the device.
-
Declaration
Swift
public var supportedAlphabets: [String]
-
A locale that defines the voice’s language.
Declaration
Swift
public var locale: Locale { get }
-
Declaration
Swift
public weak var delegate: TextToSpeechEngineDelegate? { get set }
-
Declaration
Swift
public static func isLanguageAvailable(for locale: Locale) -> Bool
-
Declaration
Swift
public func play(message: TTSMessage)
-
Declaration
Swift
public func stop()
-
Declaration
Swift
public func setVolume(_ volume: SpeechVolume)
-
Sets the language code of the messages.
Declaration
Swift
public func changeLocale(with locale: Locale) throws
Parameters
locale
The locale to change to.
Throws
TextToSpeechEngineError.unavailableLocaleInVoices
if there is no speech voice for the givenlocale
.