我不知道为什么会出现这个错误。我得到的错误是
由于未捕获的异常“com.apple.coreaudio.avfaudio”而终止应用程序,原因:“所需条件为假:_recordingTap == nil”
更新
实际上,这是可行的,但几次之后,按钮突然被禁用,麦克风不再工作。然后它会导致错误并崩溃。
你能帮我解决这个问题吗?
class ViewController: UIViewController, SFSpeechRecognizerDelegate, UITextViewDelegate, AVSpeechSynthesizerDelegate {
@IBOutlet weak var myTextView: UITextView!
@IBOutlet weak var microphoneButton: UIButton!
private let speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: "en-US"))!
private var recognitionRequest: SFSpeechAudioBufferRecognitionRequest?
private var recognitionTask: SFSpeechRecognitionTask?
private let audioEngine = AVAudioEngine()
var rightButton = UIBarButtonItem()
override func viewDidLoad() {
super.viewDidLoad()
microphoneButton.isEnabled = false
speechRecognizer.delegate = self
speechRecognizerFunc()
myTextView.delegate = self
myTextView.isUserInteractionEnabled = false
}
@IBAction func cancelButton(_ sender: UIBarButtonItem) {
self.dismiss(animated: true, completion: nil)
}
func speechRecognizerFunc(){ …Run Code Online (Sandbox Code Playgroud) 在我的 iOS 应用程序中,我尝试使用 iOS 10 的最新功能(语音 API)转录预先录制的音频。
包括文档在内的多个来源均表示,语音 API(更具体地说是 SFSpeechRecognizer)的音频持续时间限制为 1 分钟。
在我的代码中,我发现任何长度约为 15 秒或更长的音频文件都会出现以下错误。
错误域=kAFAssistantErrorDomain代码=203“SessionId=com.siri.cortex.ace.speech.session.event.SpeechSessionId@50a8e246,消息=30000毫秒后超时等待命令”UserInfo={NSLocalizedDescription=SessionId=com.siri.cortex .ace.speech.session.event.SpeechSessionId@50a8e246,消息=30000毫秒后等待命令超时,NSUnderlyingError=0x170248c40 {Error Domain=SiriSpeechErrorDomain Code=100“(null)”}}
我在互联网上进行了搜索,但未能找到解决方案。也有人遇到过同样的问题。有些人怀疑这是 Nuance 的问题。
还值得注意的是,我确实从转录过程中得到了部分结果。
这是我的 iOS 应用程序的代码。` // 创建语音识别器请求对象。让 srRequest = SFSpeechURLRecognitionRequest(url: 位置) srRequest.shouldReportPartialResults = false
sr?.recognitionTask(with: srRequest) { (result, error) in
if let error = error {
// Something wrong happened
print(error.localizedDescription)
} else {
if let result = result {
print(4)
print(result.bestTranscription.formattedString)
if result.isFinal {
print(5)
transcript = result.bestTranscription.formattedString
print(result.bestTranscription.formattedString)
// Store the transcript into the database. …Run Code Online (Sandbox Code Playgroud) 我正在构建一个支持语音识别并将语音转换为文本的搜索,因此我正在使用SFSpeechRecognizer. 但问题是我需要同时支持多种语言比如(" en_US", " fr", vi, ar)。
主要思想是用户可以说一个英语单词,另一个法语单词,我希望引擎能够检测到这一点。
目前,我正在使用它来设置我的主要语言
英语:
private let speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: "en_US"))!
Run Code Online (Sandbox Code Playgroud)
法语:
private let speechRecognizer = SFSpeechRecognizer(locale: Locale.init(identifier: "fr"))!
Run Code Online (Sandbox Code Playgroud)
每种语言我都需要单独设置。
有没有办法SFSpeechRecognizer同时支持多种语言呢?
speech-recognition voice-recognition ios swift sfspeechrecognizer
我正在尝试在我的应用程序中转录本地音频文件。短文件可以很好地识别,但如果音频超过 15 分钟,则无法识别。控制台立即显示此错误:
2020-01-17 12:57:07.528986 + 0300应用程序[2816:791131] [实用程序] + [AFAggregator logDictationFailedWithError:]错误域= kAFAssistantErrorDomain代码= 1107“(空)”
这是我的代码:
let localRecognitionRequest = SFSpeechURLRecognitionRequest(url: fileUrl)
localRecognitionRequest.shouldReportPartialResults = false
if speechRecognizer.supportsOnDeviceRecognition {
localRecognitionRequest.requiresOnDeviceRecognition = true
}
recognitionTask = speechRecognizer.recognitionTask(with: localRecognitionRequest, delegate: self)
Run Code Online (Sandbox Code Playgroud)
当出现错误时,只会触发一个委托方法:
func speechRecognitionTask(_ task: SFSpeechRecognitionTask, didFinishSuccessfully successfully: Bool) { }
Run Code Online (Sandbox Code Playgroud)
和successfully = false
我有 Xcode 11.3.1
仅在设备 - iPhone XS (iOS 13.3) 上尝试
有人遇到过这个问题吗?
我已经实现了 Apple 的 SpeechRecognizer 将语音转换为文本。我有多个录音,因此我正在创建多个 SFSpeechRecognizer 实例,以便所有这些实例都并行转换,并且我还使用了 DispatchGroup,以便我可以在最后一个结束时完成。但我不断收到错误kAFAssistantErrorDomain error 209。
private var dispatchGroup = DispatchGroup()
allURLs.forEach { (singleURL) in
DispatchQueue.main.async {
thisSelf.dispatchGroup.enter()
let request = SFSpeechURLRecognitionRequest(url: url)
guard let recognizer = SFSpeechRecognizer() else {
thisSelf.dispatchGroup.leave()
completion(.failure(thisSelf.speechReconInitError))
return
}
request.shouldReportPartialResults = false
if !recognizer.isAvailable {
thisSelf.dispatchGroup.leave()
return
}
recognizer.recognitionTask(with: request) { [weak thisSelf] (result, error) in
guard let reconSelf = thisSelf else { return }
if let error = error {
completion(.failure(error))
if let nsError = error as NSError? …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个应用程序,当用户不知道时,它会显示一个会更改每个级别的文本。目标是说出一个显示的句子(是的,它是为孩子们设计的):
\n\n@IBAction func dontknow(_ sender: Any) {\n let utterance = AVSpeechUtterance(string: textLabel.text)\n utterance.voice = AVSpeechSynthesisVoice(language: "fr-FR")\n utterance.rate = 0.4\n\n let synthesizer = AVSpeechSynthesizer()\n synthesizer.speak(utterance)\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n该应用程序的构造如下:\n如果用户不知道 -> 他可以单击按钮说出文本\n如果他是对的 -> 他进入下一个级别。
\n\n当他第一次输入要说的按钮时,应用程序会说一些话,但是当用户尝试说出文本并且在下一个级别时,他单击要说的按钮,则什么也没有发生。它只是抛出这个错误:Failure starting audio queue \xe2\x89\xa5\xcb\x9a\xcb\x9b\xcb\x87
完整代码:
\n\nimport UIKit\nimport AVFoundation\nimport Speech\n\nclass ReadViewController: UIViewController, SFSpeechRecognizerDelegate {\n var texts = ["Je mange des p\xc3\xa2tes", "Bonjour Jean comment vas-tu", "Qui est-ce", "J\'en ai marre", "Je ne te trouve pas gentil", "Pourquoi tu ne veux pas","Tu es si gentil", "Tu …Run Code Online (Sandbox Code Playgroud) speech-recognition avfoundation ios swift sfspeechrecognizer