I write the WAV files and send them to the server, but the server does not seem to recognize and manipulate the WAV files recorded on the device - any other WAV file works. Interestingly, I did something wrong with any setting AVAudioRecorder.
let settings: [String:AnyObject] = [
AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: true
]
This is the function that records the sound coming from the microphone:
var recordingSession: AVAudioSession!
var audioRecorder: AVAudioRecorder!
var audioURL = NSURL()
func startRecording() {
recordingSession = AVAudioSession.sharedInstance()
do {
try recordingSession.setCategory(AVAudioSessionCategoryRecord)
try recordingSession.setActive(true)
} catch {
}
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 {
}
}
func uploadFileAudioToServer() {
let path = "recordings/" + "userNameGoesHere" + ".wav"
amazonS3Manager.putObject(audioURL, destinationPath: path).responseS3Data({ (response) -> Void in
print("File uploaded")
})
}
What could be wrong with this method?
source
share