【问题标题】:Why SFSpeechRecognizer doesn't working in ipad为什么 SFSpeechRecognizer 在 ipad 中不起作用
【发布时间】:2021-01-29 18:47:18
【问题描述】:

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 通话中 如果 !myRecognizer.isAvailable { print("语音识别不可用") 返回 }

【问题讨论】:

    标签: ios swift ipad sfspeechrecognizer


    【解决方案1】:

    存在 SFSpeechRecognizer.isAvailable 可能返回 false 的至少两个可能原因:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-02
      • 2021-07-19
      • 1970-01-01
      • 2016-12-31
      • 2014-04-07
      相关资源
      最近更新 更多