繁体   English   中英

为什么 SFSpeechRecognizer 在 ipad 中不起作用

[英]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 存在:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM