0

I use AVSpeechSynthesizer to play text books via audio.

private lazy var synthesizer: AVSpeechSynthesizer = {
    let synthesizer = AVSpeechSynthesizer()
    synthesizer.delegate = self
    return synthesizer
  }()

let utterance = AVSpeechUtterance(string: text)
    utterance.voice = AVSpeechSynthesisVoice(
      language: languageIdentifier(from: language)
    )
    synthesizer.speak(utterance)

I want to update information in iPhone's default player view (probably naming is wrong ):

enter image description here

  • indicate playing Chapter with some text
  • enable next button to play the next chapter

How can I accomplish this?

Paul T.
  • 4,938
  • 7
  • 45
  • 93
  • Is the player connected to the speech at all? Does it pause it, or show its progress? If not, you cannot influence it at all. Synthesized speech is not a "song". – matt Nov 07 '20 at 13:43
  • @matt thank you for the answer. Aren't there any workarounds? should I start a "silent song" to accomplish it? are there any way to update information in this players info view? I mean even for songs I suppose there is a way how the developers sets information in this view? – Paul T. Nov 07 '20 at 13:49

1 Answers1

1

I really don't think you want to hack your way through this.. But if you really do I would:

  • Listen to remote commands (UIApplication.sharedApplication().beginReceivingRemoteControlEvents(), see Apple Sample Project
  • Set your properties on MPNowPlayingInfoCenter: MPNowPlayingInfoCenter.default().nowPlayingInfo[MPMediaItemPropertyTitle] = "Title"
  • Implement the AVSpeechSynthesizerDelegate and try to map the delegate functions to playback states and estimate the playback progress using speechSynthesizer(_:willSpeakRangeOfSpeechString:utterance:) (idk if possible)
  • You might have to play with the usesApplicationAudioSession property of AVSpeechSynthesizer to have more control over the audio session (set categories etc.)
fruitcoder
  • 1,073
  • 8
  • 24