[英]How to record audio on iPhone
我想用iphone錄制音頻(<2分鍾)並將其保存到文件中。 我看着SpeakHere,但它讓我很困惑。 我使用哪些課程? 我創建了哪些委托方法?
謝謝!
我同意,SpeakHere不是一個學習iPhone音頻的好起點。
iPhone音頻使用兩個概念。 AudioQueues和AudioSessions。 如果要錄制到文件,則需要創建一個AudioSession,激活會話,並創建AudioInputQueue和AudioOutputQueue。
AudioQueues的參考(到目前為止你將討論最多的部分)是:
至於AudioSessions:
雖然你可以忽略大部分AudioSession的東西,因為你不會做那么復雜的事情。 所以基本上,這里是步驟:
我沒有在這里包含所有參數,但這就是API的用途。
希望有所幫助。
[編輯]
對不起,忘了包含輸出內容,雖然它們非常簡單。 創建另一個AudioQueue,使用AudioQueueNewOutput進行初始化,API應該能夠引導您完成剩下的工作。
干杯。
本錄音音頻代碼
別忘了添加AVFoundation和AudioToolBox Framework
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"filename.caf"]];
NSLog(@"Using File called: %@",recordedTmpFile);
recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:nil];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
不再需要AudioQueues來錄制音頻。 現在使用AVAudioRecorder類是一個非常簡單的過程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.