5

I have updated to macOS Monterrey and my code for SFSPeechRecognizer just broke. I get this error if I try to configure an offline speech recognizer for macOS

Error Domain=kLSRErrorDomain Code=102 "Failed to access assets" UserInfo={NSLocalizedDescription=Failed to access assets, NSUnderlyingError=0x6000003c5710 {Error Domain=kLSRErrorDomain Code=102 "No asset installed for language=es-ES" UserInfo={NSLocalizedDescription=No asset installed for language=es-ES}}}

Here is a code snippet from a demo project:

private func process(url: URL) throws {
    speech = SFSpeechRecognizer.init(locale: Locale(identifier: "es-ES"))
    speech.supportsOnDeviceRecognition = true
    let request = SFSpeechURLRecognitionRequest(url: url)
    request.requiresOnDeviceRecognition = true
    request.shouldReportPartialResults = false
    speech.recognitionTask(with: request) { result, error in
      guard let result = result else {
        if let error = error {
          print(error)
          return
        }
        return
      }

      if let error = error {
        print(error)
        return
      }

      if result.isFinal {
        print(result.bestTranscription.formattedString)
      }
    }
  }

I have tried with different languages (es-ES, en-US) and it says the same error each time.

Any idea on how to install these assets or how to fix this?

Rodrigo
  • 733
  • 1
  • 10
  • 26

2 Answers2

0

The issue is that you're forcing it to run offline.

request.requiresOnDeviceRecognition = true

This capability requires the A12 bionic, M1, or newer SoC, because these have a neural engine. On devices without a neural engine, you need to perform speech recognition on Apple's servers.

Confuseious
  • 705
  • 9
  • 18
  • Not true! Running here offline on an A10X iPad Pro 12.9” 2nd gen… – mramosch Mar 25 '23 at 21:26
  • Thanks for that information @mramosch, I checked online and found some conflicting information. Apple says that Dictation (which I'm guessing uses the Speech framework too) works without internet connection on the A9 iPhone 6s and later, but I tried on my A9 iPad and this does not work. So it seems that you're right and the requirements might not be limited to just the SoC. Meanwhile, The Verge claims that it requires the A12 - https://www.theverge.com/2021/6/7/22522993/apple-siri-on-device-speech-recognition-no-internet-wwdc. – Confuseious Mar 26 '23 at 05:06
0

This suggestion offered in Apple's dev forums here worked, at least partially, for me:

After spending a lot of time, what worked for me was enabling and onboarding Siri for iOS. Then downloading models using Settings -> Translate -> (set on-device mode to true), then download models for the specific locale. Then run the app and waiting for some time for the models to download. (It doesn't work immediately).

I say it worked partially for me, because if I relaunch the app a few days later, the same error message appears. I need to leave the app running idle for quite a bunch of seconds (usually over a minute), which sort of makes it impossible to launch this to final users.

leandrodemarco
  • 1,552
  • 1
  • 15
  • 22