我正在录制WAV文件并将其发送到服务器,但服务器似乎无法识别和操纵设备上记录的WAV文件 - 任何其他WAV文件都能正常工作。我想知道我是否对AVAudioRecorder
的任何设置做错了。
let settings: [String:AnyObject] = [
AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: true
]
这是记录来自麦克风的音频的功能:
var recordingSession: AVAudioSession!
var audioRecorder: AVAudioRecorder!
var audioURL = NSURL()
func startRecording() {
recordingSession = AVAudioSession.sharedInstance()
do {
try recordingSession.setCategory(AVAudioSessionCategoryRecord)
try recordingSession.setActive(true)
} catch {
// failed to record!
}
let audioFilename = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
audioURL = audioFilename.URLByAppendingPathComponent("recording.wav")
let settings: [String:AnyObject] = [
AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: true
]
do {
audioRecorder = try AVAudioRecorder(URL: audioURL, settings: settings)
audioRecorder.delegate = self
audioRecorder.record()
audioRecorder.meteringEnabled = true
print("Recording...")
} catch {
// error
}
}
// I'm done! Send file to server
func uploadFileAudioToServer() {
let path = "recordings/" + "userNameGoesHere" + ".wav"
amazonS3Manager.putObject(audioURL, destinationPath: path).responseS3Data({ (response) -> Void in
print("File uploaded")
})
}
这种方法有什么问题?