Unable to play audio / speech from iOS Swift Safari Extension on gadget (OSStatus error 2003329396)

I am at the moment making an attempt to make use of AVSpeechSynthesizer to talk textual content from inside an iOS Safari extension:

let synthesizer = AVSpeechSynthesizer()

let utterance = AVSpeechUtterance(string: self.textual content)
utterance.fee = 0.55;

On a simulator this works high quality. Nonetheless, on a bodily gadget, I get the next error (even when the gadget is unmuted/volume-up):

NSURLConnection completed with error - code -1002
NSURLConnection completed with error - code -1002
NSURLConnection completed with error - code -1002
[AXTTSCommon] Failure beginning audio queue alp!
[AXTTSCommon] Run loop timed out ready at no cost audio buffer
[AXTTSCommon] _BeginSpeaking: speech cancelled error: Error Area=TTSErrorDomain Code=-4001 "(null)"
[AXTTSCommon] _BeginSpeaking: could not start playback

I’ve regarded by way of fairly a couple of SO and Apple Dev Boards threads and have tried lots of the proposed options with no luck. Listed here are the issues I’ve tried:

  1. Linking AVFAudio.framework and AVFoundation.framework to the extension.

  2. Beginning an AVAudioSession previous to taking part in the utterance:

do {
    let session = AVAudioSession.sharedInstance()
    strive session.setCategory(.playback, mode: .default, choices: [.mixWithOthers, .allowAirPlay])
    strive session.setActive(true, choices: .notifyOthersOnDeactivation)
} catch let error {
    print("Error beginning audio: (error.localizedDescription)")

This really leads to one other error being thrown proper earlier than the identical errors above:

Error beginning audio: The operation couldn’t be accomplished. (OSStatus error 2003329396.)
  1. Enjoying a plain mp3 audio file:
guard let url = Bundle.foremost.url(forResource: "pattern", withExtension: "mp3") else {
    print("Could not discover file")

do {
    self.participant = strive AVAudioPlayer(contentsOf: url)
    print("**taking part in sound")
} catch let error as NSError {
    print("Error taking part in sound: (error.localizedDescription)")

This prints the next:

**taking part in sound
[aqsrv]              AQServer.cpp:72    Exception caught in AudioQueueInternalNotifyRunning - error -66671
  1. Enabling Audio, AirPlay, and Image in Image in Background Modes for the principle goal app (not obtainable for the extension).

Any assist can be appreciated.

Leave a Reply