SFSpeechRecognizer 多种语言 [英] SFSpeechRecognizer multiple languages
问题描述
我正在构建一个支持语音识别并将语音转换为文本的搜索,因此我使用了 SFSpeechRecognizer
.但是问题是我需要同时支持多种语言比如 ("en_US
", "fr
", vi
, <代码>ar).
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
英文:
private let speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: "en_US"))!
法语:
private let speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: "fr"))!
每种语言我都需要单独设置.
Every language I need to set it separately.
有没有办法让 SFSpeechRecognizer
同时支持多种语言?
Is there a way so SFSpeechRecognizer
supports multiple languages at the same time?
推荐答案
老问题,但还没有答案...
Old question, but no answer yet...
您不能在一个 SFSpeechRecognizeer
中使用更多的语言环境,但您可以同时管理多个 SFSpeechRecognizer
,如下所示:
You cannot use more locale in just one SFSpeechRecognizeer
, but you can manage multiple SFSpeechRecognizer
s at the same time, like this:
let italian = SFSpeechRecognizer(locale: Locale(identifier: "it-IT"))
let english = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))
为所有这些设置委托:
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
})
等等...
对于您的具体要求:
主要思想是用户可以用英语说例如1个单词另一个是法语,我希望引擎检测到这一点.
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.
这篇关于SFSpeechRecognizer 多种语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!