NSSpeechSynthesizer deadlocks when writing to a file and calling stopSpeaking

Originator:steve
Number:rdar://36138159 Date Originated:19-Dec-2017 12:38 PM
Status:Open Resolved:
Product:macOS + SDK Product Version:10.13.2
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
In macOS 10.13.2, it is very easy to create a deadlock when using NSSpeechSynthesizer. 

Steps to Reproduce:
On macOS 10.13.2: Create a new macOS Cocoa project in Xcode. In applicationDidFinishLaunching of the AppDelegate, create an NSSpeechSynthesizer, call startSpeaking and pass a url and a long string of text, then wait a few seconds and call stopSpeaking. If you enter the debugger, you’ll see that the NSSpeechSynthesizer is deadlocked in that stopSpeaking call.

In my attached example AppDelegate.swift, the alert is never shown.

Expected Results:
I expect the thread to not deadlock, and to show the alert. This works properly on macOS versions earlier than 10.13.2.

Actual Results:
The main thread — or whatever thread you call stopSpeaking on — is deadlocked. We never see the alert.

Version:
10.13.2

Notes:
The code works as desired before macOS 10.13.2.

Code:

```
import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!

    let text = "Lorem ipsum dolor sit amet consectetur adipiscing elit, phasellus elementum lobortis quisque aptent leo a, rutrum dictum velit nostra viverra mollis. Nam pharetra feugiat sollicitudin quisque consequat suspendisse nisi blandit purus nascetur proin mi, fermentum magna felis et aenean condimentum ultrices justo vulputate etiam fusce, turpis id netus tristique porta libero hendrerit scelerisque semper fringilla placerat. Accumsan nisl felis nascetur lorem vulputate metus mauris aliquet purus, rutrum non viverra dictumst mi commodo mollis risus, sociis ullamcorper integer tincidunt donec himenaeos porta vestibulum. Senectus torquent per odio viverra mauris dui lacus nisi ligula porta pretium ornare purus amet, ad cursus suspendisse dis porttitor nec enim class nunc leo ante cras tempor. Mollis posuere cum gravida a primis et donec mauris, sagittis sit duis nulla hac penatibus imperdiet amet montes, libero mattis blandit urna orci fringilla vestibulum. Vehicula porta tempor augue fringilla fames pellentesque feugiat sagittis, quis lobortis lectus phasellus class sapien vulputate senectus, volutpat duis erat tellus fusce ultricies morbi. Id cubilia malesuada consectetur quisque tempus mattis a, vulputate aliquet elementum non laoreet penatibus auctor, hac ad neque pharetra magnis amet."

    var synth: NSSpeechSynthesizer?

    func applicationDidFinishLaunching(_ aNotification: Notification) {

        let url = URL(fileURLWithPath: "\(NSTemporaryDirectory())/\(UUID().uuidString).aiff")

        synth = NSSpeechSynthesizer()
        synth?.startSpeaking(text, to: url)

        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) {
            self.synth?.stopSpeaking()
            let alert = NSAlert()
            alert.messageText = "After 'stopSpeaking'"
            alert.runModal()
        }
    }
}
```

Comments

Different experiences with different hardware

  1. I too tried to use NSSpeechSynthesizer startSpeaking(_:to:) to generate some AIFF speech files but my app froze in a similar way (except I am on macOS v10.13.3).
  2. When troubleshooting I noticed the macOS Accessibility Speech Control had also frozen with its "System Voice:" Text Field stuck on "Loading Voices...".
  3. I then thought it may be a hardware issue so I put my app onto a newer machine, and bingo, it worked fine without a problem.
  4. Both machines run macOS v10.13.3 & Xcode v9.2, but the (older) machine is a Late 2015 iMac (4 GHz Intel Core i7), and the (newer) machine is a 2017 MacBook (1.3 GHz Intel Core i5).
By aus0411042453 at March 15, 2018, 6:03 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!