apraka16 / iOSAR

AR Project - iOS (Swift)
7 stars 3 forks source link

On using AVSpeech... objects, warnings: TTSPlaybackCreate unable to init dynamics #13

Closed apraka16 closed 6 years ago

apraka16 commented 6 years ago

Warning: 2017-12-02 19:54:00.302555+0530 ARKitBasics[434:108636] [TTS] TTSPlaybackCreate unable to initialize dynamics: -3000

apraka16 commented 6 years ago

This probably has to do with issues with iOS itself rather than bug with current codebase.

apraka16 commented 6 years ago
apraka16 commented 6 years ago

private var voice = AVSpeechSynthesisVoice(identifier: "com.apple.ttsbundle.siri_female_en-US_compact") choice of voice seems to be the problem owing to which the warning is being issued. Additionally, sound crashes at times, which is a more severe issue.

KonradMaroszek commented 6 years ago

Hi did you solve the problem ?, I have the same issue in my application. What's more, it only occurs in three places in whole app. I suspect that it has a connection with threads. Unfortunately, I was unable to find a solution yet.

apraka16 commented 6 years ago

Hey, yeah probably it is. I am using global threads for handling the voices. However, note that in my case the voice works. It's just that there are warning issued. As much as I have googled about it and fiddled with choice of my voice problem seems to be stemming from choice of voice. But till now no solution. Still looking for it.

KonradMaroszek commented 6 years ago

I do not choose the voice, I use the user's choice in the system options and the problem still occurs. The application is multilingual, the problem occurs for every country. If I fix something, I'll let you know. Good luck :)

KonradMaroszek commented 6 years ago

I solved my problem. One view was starting speaking when another was stopping (in didDisapear function)

apraka16 commented 6 years ago

In such cases, I use interruption, as:

    func sayWithInterruption(text: String) {
        if self.isSpeaking {
            self.stopSpeaking(at: AVSpeechBoundary.immediate)
        }
        let speechUtterance = AVSpeechUtterance(string: text)
        speechUtterance.voice = voice
        speechUtterance.rate = 0.5
        self.speak(speechUtterance)
}

I wonder did it really stop? The warning? What was the solution?

KonradMaroszek commented 6 years ago

I'm using small hack:

sometimes when you call speak and stop in short intervals AVSpeechSynthesizer return isSpeaking==true even though the class did not read... After each cancellation, i create a new instance of synthesizer to avoid this situation. I know it is not elegant way but it works. I think it is bug in apple code.

it is part of my code:

func cancelReading() - Void { my code

self.stopSpeaking(at: AVSpeechBoundary.immediate)

synthesizer = AVSpeechSynthesizer()

synthesizer.delegate = self

currentlyReading = nil
sequence.removeAll()

*** my code ***

}

apraka16 commented 6 years ago

Ah, new instances! Yeah, probably it is a bug I suppose, I will incorporate this in my code as well and see what happens, if it works for you though I am sure it would for me as well. Thanks.

apraka16 commented 6 years ago

Reported bug to Apple https://bugreport.apple.com/web/?problemID=36339935

apraka16 commented 6 years ago

Apple Developer Relations January 25 2018, 10:08 PM There are no plans to address this based on the following:

The only way we’ve been able to reproduce this here is by performing access to the same synthesizers on several threads simultaneously.

Based on your github reference it looks like you are interfacing with the synthesizer on the global concurrent queues.

Suggest you interact with an instance of the speech synthesizer on a serial queue instead.

We are now closing this report.

If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.

Please be sure to regularly check new Apple releases for any updates that might affect this issue.

apraka16 commented 6 years ago

Though Apple has prescribed the use of serial queue, and I've tried using the same, somehow this issue is cropping up despite that. However, creating AVSynth object every time speech is needed does serve the purpose. On analysing ARC in Instruments, AV Synth objects which are not used anymore are flushed out (deallocated) by the system which contains the memory hence is good enough to go.