通过recognitionTask传递音频文件路径和请求时获取错误

时间:2017-05-04 10:51:13

标签: ios objective-c swift

我正在尝试将音频实现为文字,音频播放效果不错,但当RecognitionRequest通过recognitionTask时显示错误

:Error is:Error Domain=kAFAssistantErrorDomain Code=1101 "(null)"

并获得null

我的代码是:

func requestSpeechMethod()
    {
        SFSpeechRecognizer.requestAuthorization {authenticateStatus in

            if authenticateStatus == SFSpeechRecognizerAuthorizationStatus.authorized {
                if let path = Bundle.main.url(forResource: "2", withExtension: "mp3")
                {
                    do {
                        //----------------------------------------
                        let audio = try AVAudioPlayer(contentsOf: path)
                        self.audioPlayer = audio
                        self.audioPlayer.delegate = self
                        audio.play()
                        //----------------------------------------
                    }
                    catch
                         {
                        print("Error")
                    }
                    //----------------------------------------
                    let recognizer = SFSpeechRecognizer()
                    let request = SFSpeechURLRecognitionRequest(url: path)
                    recognizer?.recognitionTask(with: request) { (result,error) in
                        //---------------------
                        if let error = error {
                            print("Error is:\(error)")
                        } else
                           {
                            self.textVOutlet.text = result?.bestTranscription.formattedString
                        }
                        //---------------------
                    }
                }
                   //----------------------------------------
            }
        }
    }

0 个答案:

没有答案