Ces*_*are 5 audio objective-c avfoundation ios swift
我正在记录WAV文件并将其发送到服务器,但是服务器似乎无法识别和处理设备上记录的WAV文件-其他任何WAV文件都可以使用。我不知道在设置时是否做错了什么AVAudioRecorder。
let settings: [String:AnyObject] = [
AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: true
]
Run Code Online (Sandbox Code Playgroud)
此功能可以记录来自麦克风的音频:
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")
})
}
Run Code Online (Sandbox Code Playgroud)
这种方法有什么问题?
| 归档时间: |
|
| 查看次数: |
368 次 |
| 最近记录: |