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.")
}
}
}