我正在使用AVAudioRecorder添加语音备忘录功能,我需要知道录音机录制语音的最佳设置.
不幸的是,我对音频一无所知,甚至不确定google的条款.
目前,我正在使用以下内容从某处复制以进行测试:
recorderSettingsDict=[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:kAudioFormatAppleIMA4],AVFormatIDKey,
[NSNumber numberWithInt:44100.0],AVSampleRateKey,
[NSNumber numberWithInt: 2],AVNumberOfChannelsKey,
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
nil];
Run Code Online (Sandbox Code Playgroud)
要么:
defaultSettings = {
AVFormatIDKey = 1768775988;
AVLinearPCMBitDepthKey = 16;
AVLinearPCMIsBigEndianKey = 0;
AVLinearPCMIsFloatKey = 0;
AVNumberOfChannelsKey = 2;
AVSampleRateKey = 44100;
};
Run Code Online (Sandbox Code Playgroud)
这有效,但我不知道它在质量,速度,文件大小等方面是否适合语音.
该AVAudioRecorder类参考列出许多设置的常量,但我不知道那些使用语音其中.
如果有人知道一个好的"AudioFormats for Dummy"资源,我也会这样做.(注意:我已经浏览过Apple Docs,他们假设我没有数字音频知识库.)
有没有办法录制到音频文件的末尾?我们不能暂停录制而不是停止录制,因为用户需要以后能够返回应用并为录制添加更多音频.目前,音频作为NSData存储在CoreData中.NSData AppendData不起作用,因为生成的音频文件仍然报告它只与原始数据一样长.
另一种可能性是将原始音频文件与新音频文件连接起来,并将它们连接成一个音频文件,如果有任何方法可以做到这一点.
我的应用程序使用带有音频参数的AVAudioRecorder逐个记录两个音频文件:
NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],AVEncoderBitDepthHintKey,
[NSNumber numberWithInt:128000], AVEncoderBitRateKey,
nil];
Run Code Online (Sandbox Code Playgroud)
我需要在file1的末尾添加file2.我正在使用那里的解决方案(通过在添加两个文件并使用exportAsynchronouslyWithCompletionHandler:AVAssetExportSession方法导出合成后创建AVMutableCompositionTrack来附加两个音频文件).
它有效,但我有两个输入文件128kbs 44.1kHz 16bit单声道,输出文件格式为:219.4kbs 44.1kHz 16bit立体声.
有没有办法为AVAssetExportSession配置输出音频文件参数?
我知道这个问题遍布 Stack Overflow,但其中大多数都是旧问题,与我要在这里问的问题无关。
所以我有一个带有AVPlayerItems和 的数组AVQueuePlayer。首先,我设置 AVQueuePlayer 来播放数组项目:
func mediaPicker(mediaPicker: MPMediaPickerController!, didPickMediaItems mediaItemCollection: MPMediaItemCollection!) {
mediaItems = mediaItemCollection.items
for thisItem in mediaItems as [MPMediaItem] {
var itemUrl = thisItem.valueForProperty(MPMediaItemPropertyAssetURL) as? NSURL
var playerItem = AVPlayerItem(URL: itemUrl)
mediaArray.append(playerItem)
}
updateMetadata()
audioPlayer = AVQueuePlayer(items: mediaArray)
self.dismissViewControllerAnimated(true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
但是,例如,当用户添加新项目或删除项目时,我尝试更新播放器(与我首先设置它的方式相同),但它给了我错误。我想知道是否有任何解决办法,或者有什么解决方案。这是用户删除歌曲的方式:
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete{
mediaArray.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
audioPlayer = AVQueuePlayer(items: mediaArray) //here gives the error
}
}
Run Code Online (Sandbox Code Playgroud)
我为此自杀了,所以,如果有人能帮助我,我将不胜感激。