谁能告诉我在 ios 应用程序中录音的最佳录音功能是啥
Posted
技术标签:
【中文标题】谁能告诉我在 ios 应用程序中录音的最佳录音功能是啥【英文标题】:Can any one tell me which is the best voice recording functionality for voice recording in ios app谁能告诉我在 ios 应用程序中录音的最佳录音功能是什么 【发布时间】:2015-08-28 06:12:03 【问题描述】:谁能告诉我在 ios 应用程序中哪个是最好的录音功能...我。我可能做错了什么。请帮我解决这个问题。
【问题讨论】:
***.com/questions/5602901/… 录音功能?录音是由硬件完成的,不是吗?我知道使用 Audacity 之类的音频软件来消除噪音的唯一方法是对整个声音文件中重复的噪音进行采样,然后告诉 Audacity 删除任何类似于样品。它并不完美,如果做得太多,会导致音频开始发出唧唧声/高音/噼啪声。 【参考方案1】: #import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController<AVAudioRecorderDelegate,AVAudioPlayerDelegate>
AVAudioRecorder *recorder;
AVAudioPlayer *player;
- (void)viewDidLoad
[super viewDidLoad];
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"youraudiofile.m4a",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
//setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:nil];
//defining recorder settings
NSMutableDictionary *recorderSettings = [[NSMutableDictionary alloc]init];
[recorderSettings setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recorderSettings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recorderSettings setValue:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
//Initiate and preparing recorder
recorder = [[AVAudioRecorder alloc]initWithURL:outputFileURL settings:recorderSettings error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];
-(IBAction)btnVoiceRecordClicked:(id)sender
if (player.playing)
[player stop];
if (!recorder.recording)
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[session setActive:YES error:nil];
//start recording
[recorder record];
-(IBAction)btnStopRecordClicked:(id)sender
[recorder stop];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
-(IBAction)btnPlayRecordClicked:(id)sender
if (!recorder.recording)
NSError *error = nil;
player = [[AVAudioPlayer alloc]initWithContentsOfURL:recorder.url error:&error];
player.delegate = self;
[player play];
if (error != nil)
NSLog(@"%@",error.localizedDescription);
【讨论】:
【参考方案2】:我不知道,天气是最好还是最坏,但它对我有用,它满足了我的要求。
#import "RecoderViewController.h"
#import <AVFoundation/AVFoundation.h>
#import<AudioToolbox/AudioToolbox.h>
#import "PhotoViewController.h"
#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
@interface RecoderViewController ()
NSMutableDictionary *recordSetting;
NSString *recorderFilePath;
AVAudioRecorder *recorder;
NSMutableDictionary *editedObject;
NSTimer *timer;
int i,j;
NSString *str;
@end
@implementation RecoderViewController
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view.
i=00;
j=00;
str = @"reco";
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (IBAction)clicktorecord:(id)sender
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES];
self.imageRecord.hidden = false;
self.btnStart.hidden = true;
self.btnStop.hidden =false;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err)
NSLog(@"audioSession: %@ %ld %@", [err domain], (long)[err code], [[err userInfo] description]);
return;
[audioSession setActive:YES error:&err];
err = nil;
if(err)
NSLog(@"audioSession: %@ %ld %@", [err domain], (long)[err code], [[err userInfo] description]);
return;
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
// Create a new dated file
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *caldate = [now description];
recorderFilePath = [NSString stringWithFormat:@"%@/%@.caf", DOCUMENTS_FOLDER, caldate];
NSURL *url = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
if(!recorder)
NSLog(@"recorder: %@ %ld %@", [err domain], (long)[err code], [[err userInfo] description]);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: [err localizedDescription]
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
//prepare to record
[recorder setDelegate:self];
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
BOOL audioHWAvailable = audioSession.inputIsAvailable;
if (! audioHWAvailable)
UIAlertView *cantRecordAlert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: @"Audio input hardware not available"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[cantRecordAlert show];
// start recording
[recorder recordForDuration:(NSTimeInterval) 10];
-(void)updateCountdown
i++;
if (i>60)
j=j+1;
i=0;
self.lblTimer.text =[NSString stringWithFormat:@"%d : %d",j,i];
- (IBAction)ClicktoStop:(id)sender
self.btnStart.hidden =false;
self.btnStop.hidden =true;
self.imageRecord.hidden = true;
[timer invalidate];
[recorder stop];
NSURL *url = [NSURL fileURLWithPath: recorderFilePath];
NSError *err = nil;
NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err];
if(!audioData)
NSLog(@"audio data: %@ %ld %@", [err domain], (long)[err code], [[err userInfo] description]);
[editedObject setValue:[NSData dataWithContentsOfURL:url] forKey:@"editedFieldKey"];
[self performSegueWithIdentifier:@"gotoshare" sender:self];
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *) aRecorder successfully:(BOOL)flag
NSLog (@"audioRecorderDidFinishRecording:successfully:");
【讨论】:
我做了同样的过程,但我得到了背景噪音。例如它正在捕捉风扇声音,键盘声音。我应该怎么做才能减少这些。 sry 兄弟,即使我可以减少它 感谢您帮助您发帖。以上是关于谁能告诉我在 ios 应用程序中录音的最佳录音功能是啥的主要内容,如果未能解决你的问题,请参考以下文章