当前位置: 代码迷 >> Iphone >> 话音(LCVoiceHudDemo)
  详细解决方案

话音(LCVoiceHudDemo)

热度:41   发布时间:2016-04-25 05:45:25.0
语音(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];}

 

  相关解决方案