我正在尝试将音频实现为文字,音频播放效果不错,但当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
}
//---------------------
}
}
//----------------------------------------
}
}
}