我正在尝试在视图控制器中使用语音识别 我已经编写了以下代码但是收到了错误:
swift error domain=nsosstatuserrordomain code=2003334207 "(null)"
我还在File.m4a的根目录下创建了一个音频文件,但是在下面的第2行之后得到nil错误是代码:
case .authorized:
isButtonEnabled = true
do{
Linenumber = "1"
let path = Bundle.main.url(forResource: "File", withExtension: "m4a")
Linenumber = "2"
let sound = try AVAudioPlayer(contentsOf: path!)
Linenumber = "3"
self.audioPlayer = sound
Linenumber = "4"
self.audioPlayer.delegate = self
Linenumber = "5"
sound.play()
let recognizer = SFSpeechRecognizer()
Linenumber = "6"
let request = SFSpeechURLRecognitionRequest(
url: path!)
Linenumber = "7"
recognizer?.recognitionTask(with: request, resultHandler: {
(result, error) in
Linenumber = "8"
self.meetingnotes.text = self.meetingnotes.text + " " + (result?.bestTranscription.formattedString)!
})
}
请让我知道我哪里出错了。 PS。我已经在Info.plist中创建了一个条目 感谢