作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如何以 iLBC 格式录制音频?我从问题 # 1010343 得到了一些帮助,并实现了这段代码:
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] initWithCapacity:10];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
// [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; // doesn't work: no error, but no sound
// [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatiLBC] forKey:AVFormatIDKey]; // doesn't work: no error, but not sound
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSetting setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];
recorder = [[AVAudioRecorder alloc] initWithURL:audioFile settings:recordSetting error: &avError ];
[recorder setDelegate:self];
[recorder recordForDuration:(NSTimeInterval) secLeft];
[recorder record];
和上面一样,它工作正常。好录音。轻松播放。您注意到其他格式被注释掉了。如果我尝试其中任何一个,我什么也得不到。我想要更小的文件,根据问题 # 7279643 ,它提供了这个有值(value)的信息:
Here are the results for few encoding supported by iPhone:
Size of audio file of duration 10 sec.
kAudioFormatMPEG4AAC : 164 kB
kAudioFormatAppleLossless : 430 kB
kAudioFormatAppleIMA4 : 475 kB
kAudioFormatULaw : 889 kB
kAudioFormatALaw : 889 KB
我应该可以在 iLBC 中录制。但如果我尝试,我什么也得不到。当我使用 IMA4 格式以外的格式时,是否需要在录制或播放中更改其他内容?
这是我的播放代码:
NSError *avError;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&avError];
[audioSession setActive:YES error:&avError];
if( !avError ) {
if( [audioPlayer isPlaying] ) {
[audioPlayer stop ];
}
while( ![audioPlayer isPlaying] ) {
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFile error:nil];
self.audioPlayer = player;
self.audioPlayer.numberOfLoops = 0;
[audioPlayer prepareToPlay];
[audioPlayer play];
}
} else {
NSLog(@"Playback Error: %@", avError );
}
最佳答案
通过删除修复它:
[recordSetting setValue:[NSNumber numberWithFloat:44100.0]forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]
我猜它们与 iLBC 默认值冲突。
关于iphone - 我想要 iLBC 格式,但似乎只能录制 IMA4 格式的音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13098632/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!