1
這裏後,文件路徑,我用它來使音頻文件中的代碼,似乎一切都在這裏很好的工作:錄音文件,無法得到記錄
func startRecording() {
let audioFilename = getDocumentsDirectory().appendingPathComponent("Meeting_Audio.m4a")
let settings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
AVSampleRateKey: 12000,
AVNumberOfChannelsKey: 1,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]
do {
audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)
audioRecorder.delegate = self
audioRecorder.record()
} catch {
finishRecording(success: false)
}
}
func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool) {
makeFileData()
}
@IBAction func onEndMeetingButtonClicked(_ sender: UIButton) {
finishRecording(success: true)
}
func finishRecording(success: Bool) {
audioRecorder.stop()
audioRecorder = nil
if success {
print("recording succeeded :)")
} else {
print("recording failed :(")
}
}
這裏是一個簡化版本我的功能,仍然再現問題。我從audioRecorderDidFinishRecording
調用這個函數。我似乎無法獲得文件路徑。
func makeFileData() {
if let filePath = Bundle.main.path(forResource: "Meeting_Audio", ofType: "m4a"){
print("File path loaded.")
if let fileData = NSData(contentsOfFile: filePath) {
print("File data loaded.")
}
}
}