首页 > 代码库 > 语音(LCVoiceHudDemo)

语音(LCVoiceHudDemo)

代码:

- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.            voice = [[LCVoice alloc] init];       UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];    button.frame = CGRectMake(self.view.frame.size.width/2-50, self.view.frame.size.height-100, 100, 100);    [button setTitle:@"录制" forState:UIControlStateNormal];    [button addTarget:self action:@selector(recordStart) forControlEvents:UIControlEventTouchDown];    [button addTarget:self action:@selector(recordEnd) forControlEvents:UIControlEventTouchUpInside];    [button addTarget:self action:@selector(recordCancel) forControlEvents:UIControlEventTouchUpOutside];    [self.view addSubview:button];}-(void) recordStart{    [voice startRecordWithPath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];}-(void) recordEnd{    [voice stopRecordWithCompletionBlock:^{                if (voice.recordTime > 0.0f) {            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"\nrecord finish ! \npath:%@ \nduration:%f",voice.recordPath,voice.recordTime] delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];            [alert show];         }            }];}-(void) recordCancel{    [voice cancelled];        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:@"取消了" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];    [alert show];}

 

语音(LCVoiceHudDemo)