I'm using Apple's Text-to-Speech (AVSpeechSynthesizer) to speak text. I want to know how to fast forward and backward current speech. For instance, jump forward 15 seconds or backward 15 seconds.
Searched around of Google, didn't see any related topic. Is this supported?
// Create a speech synthesizer.
private var synthesizer = AVSpeechSynthesizer()
// Used as highlight word of Text-to-Speech
@Published var attributedText: NSAttributedString?
override init() {
super.init()
synthesizer.delegate = self
}
private func createUtterance(_ text: String) -> AVSpeechUtterance {
// Create an utterance.
let utterance = AVSpeechUtterance(string: text)
// Configure the utterance.
utterance.rate = 0.5
utterance.pitchMultiplier = 0.8
utterance.postUtteranceDelay = 0.2
utterance.volume = 0.8
// Retrieve the British English voice.
let voice = AVSpeechSynthesisVoice(language: "en-US")
// Assign the voice to the utterance.
utterance.voice = voice
return utterance
}
func speak(_ text: String) {
let utterance = createUtterance(text)
synthesizer.speak(utterance)
}
func pauseSpeaking(at boundary: AVSpeechBoundary = .word) {
synthesizer.pauseSpeaking(at: boundary)
}
func continueSpeaking() {
synthesizer.continueSpeaking()
}
var isSpeaking: Bool {
synthesizer.isSpeaking
}
var isPaused: Bool {
synthesizer.isPaused
}