0

Can any one tell me which is the best voice recording functionality for voice recording in ios app...Is there any third party api which work great with out any noise capture... I tried Novocain but didn't worked for me.May I am doing some where wrong.Please help me out with this issue.

Tejaswi iitv
  • 71
  • 1
  • 9
  • http://stackoverflow.com/questions/5602901/how-to-record-audio-through-an-iphone-app – Solid Soft Aug 28 '15 at 06:29
  • Voice recording functionality ? Sound recording is done by the hardware, no ? The only way to cancel noise that' I'm aware of using an Audio Software like Audacity is to take a sample of the noise that is repeated in the entire sound file, then tell Audacity to delete any pattern of wave lengths that are similar to the sample. It's not perfect and causes the audio to start having chirpy/high pitch/crackling sound if done too much. – Zhang Aug 28 '15 at 07:38

2 Answers2

0

I don't know, Weather it is best or wrost, But it is worked for me and it is fullfilled my requirement.

#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:");


}
Hitesh Surani
  • 12,733
  • 6
  • 54
  • 65
0
    #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);
        }
    }
}
Maksud Ali
  • 121
  • 4