ios의 녹음

1659 단어
코드:
#import "ViewController.h"
#import 

@interface ViewController ()

/**      */
@property (nonatomic, strong) AVAudioRecorder *recorder;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}



- (IBAction)startBtn {
    
    
    // 6.    
    [self.recorder record];
    
}

- (IBAction)stopBtn {
    //     
    [self.recorder stop];
}

#pragma mark -      
- (AVAudioRecorder *)recorder{
    if (_recorder == nil) {
        // 1.      
        NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        
        NSLog(@"%@",path);
        
        // 2.      
        NSString *filePath = [path stringByAppendingPathComponent:@"123.caf"];
        
        // 3.   URL
        NSURL *url = [NSURL fileURLWithPath:filePath];
        
        // 4.       
        NSDictionary *settingRecorder = @{
                                          AVEncoderAudioQualityKey : [NSNumber numberWithInteger:AVAudioQualityLow],
                                          AVEncoderBitRateKey : [NSNumber numberWithInteger:16],
                                          AVSampleRateKey : [NSNumber numberWithFloat:8000],
                                          AVNumberOfChannelsKey : [NSNumber numberWithInteger:2]
                                          };
        
        // 5.      
        self.recorder = [[AVAudioRecorder alloc]initWithURL:url settings:settingRecorder error:nil];
    }
    return _recorder;
}

좋은 웹페이지 즐겨찾기