5

I am building a search that supports voice recognition and transforms speech to text so I am using SFSpeechRecognizer. But the problem is that I need to support multiple languages at the same time such as ("en_US", "fr", vi, ar).

The main idea is that the user can speak for example 1 word in English and the other in French and I want the engine to detect this.

Currently, I am using this to set my main language

ENGLISH:

private let speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: "en_US"))!

FRENCH:

 private let speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: "fr"))!

Every language I need to set it separately.

Is there a way so SFSpeechRecognizer supports multiple languages at the same time?

JhonnyTawk
  • 834
  • 11
  • 23

1 Answers1

0

Old question, but no answer yet...

You cannot use more locale in just one SFSpeechRecognizeer, but you can manage multiple SFSpeechRecognizers at the same time, like this:

let italian = SFSpeechRecognizer(locale: Locale(identifier: "it-IT"))
let english = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))

set delegate for all of them:

italian.delegate = self
english.delegate = self

create double, triple or multiple logic as needed like:

self.recognitionTaskOne = italian?.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
     // Your code
})
self.recognitionTaskTwo = english?.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
     // Your code
})

and so on...

For your specific request:

The main idea is that the user can speak for example 1 word in English and the other in French and I want the engine to detect this.

I'm affraid that you need to process all the outputs and compare them. Anyway, I noticed that if I set one locale (for example Italian) and then the user speaks in English, the system gets some English too. This works just for English... I'm not sure, but I suppose that whatever locale you set, English is always understood by default.

Giuseppe Garassino
  • 2,272
  • 1
  • 27
  • 47
  • HI @Giuseppe Garassino I have tried but for one of my request i am getting SpeechApp[4764:92774] [Utility] +[AFAggregator logDictationFailedWithError:] Error Domain=kAFAssistantErrorDomain Code=203 "Retry" UserInfo={NSLocalizedDescription=Retry, NSUnderlyingError=0x600001c71470 {Error Domain=SiriSpeechErrorDomain Code=1 "(null)"}} – Beena Sep 14 '22 at 05:24