[英]Why SFSpeechRecognizer doesn't working in ipad
SFSpeechRecognizer 在 IOS 中運行良好,但在 IPAD 中不可用。 我不知道如何修復它。 請給我一個解決方案。
func recordAndRecognizeSpeech() {
let node = audioEngine.inputNode
let recordingFormat = node.outputFormat(forBus: 0)
node.installTap(onBus: 0, bufferSize: 0, format: recordingFormat) { buffer, _ in
self.request.append(buffer)
}
audioEngine.prepare()
do {
try audioEngine.start()
} catch {
return print(error)
}
guard let myRecognizer = SFSpeechRecognizer() else {
// A recognizer is not supported for the current locale
return
}
if !myRecognizer.isAvailable {
print("Speech recognition not available")
return
}
isFinal = false
recognitionTask = speechRecognizer?.recognitionTask(with: request, resultHandler: { result, error in
if let result = result {
self.recognizedSpeechTextView.text = result.bestTranscription.formattedString
self.qnaTextField.text = result.bestTranscription.formattedString
self.textFieldDidChange(self.qnaTextField)
} else if let error = error {
print(error)
}
if !self.isFinal {
self.startSpeechTimer()
}
})
}
在 iPad 調用函數中 if !myRecognizer.isAvailable { print("語音識別不可用") return }
至少有兩個可能的原因 SFSpeechRecognizer.isAvailable 可能返回 false 存在:
嘿 Siri 未在設備上啟用。 切換設置 -> Siri 和搜索 -> 聆聽“嘿 Siri”(iOS 15)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.