iphone - AVCaptureSession With STT(Speech to text) -
i using avcapture
session record video same time using stt(google speech text api) convert voice text. have facing problem when click on speak button camera freezes. correct answer acceptable. in advance .
to start camera in
-(void)viewdidload; if ([[self capturemanager] setupsession]) { // create video preview layer , add ui avcapturevideopreviewlayer *newcapturevideopreviewlayer = [[avcapturevideopreviewlayer alloc] initwithsession:[[self capturemanager] session]]; uiview *view = [self videopreviewview]; calayer *viewlayer = [view layer]; [viewlayer setmaskstobounds:yes]; cgrect bounds = [view bounds]; [newcapturevideopreviewlayer setframe:bounds]; if ([newcapturevideopreviewlayer isorientationsupported]) { [newcapturevideopreviewlayer setorientation:avcapturevideoorientationlandscapeleft|avcapturevideoorientationlandscaperight]; } [newcapturevideopreviewlayer setvideogravity:avlayervideogravityresizeaspectfill]; [viewlayer insertsublayer:newcapturevideopreviewlayer below:[[viewlayer sublayers] objectatindex:0]]; [self setcapturevideopreviewlayer:newcapturevideopreviewlayer]; [newcapturevideopreviewlayer release]; // start session. done asychronously since -startrunning doesn't return until session running. dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ [[[self capturemanager] session] startrunning]; }); [self updatebuttonstates]; } - (bool) setupsession { bool success = no; // set torch , flash mode auto if ([[self backfacingcamera] hasflash]) { if ([[self backfacingcamera] lockforconfiguration:nil]) { if ([[self backfacingcamera] isflashmodesupported:avcaptureflashmodeauto]) { [[self backfacingcamera] setflashmode:avcaptureflashmodeauto]; } [[self backfacingcamera] unlockforconfiguration]; } } if ([[self backfacingcamera] hastorch]) { if ([[self backfacingcamera] lockforconfiguration:nil]) { if ([[self backfacingcamera] istorchmodesupported:avcapturetorchmodeauto]) { [[self backfacingcamera] settorchmode:avcapturetorchmodeauto]; } [[self backfacingcamera] unlockforconfiguration]; } } // init device inputs avcapturedeviceinput *newvideoinput = [[avcapturedeviceinput alloc] initwithdevice:[self frontfacingcamera] error:nil]; avcapturedeviceinput *newaudioinput = [[avcapturedeviceinput alloc] initwithdevice:[self audiodevice] error:nil]; // setup still image file output avcapturestillimageoutput *newstillimageoutput = [[avcapturestillimageoutput alloc] init]; nsdictionary *outputsettings = [[nsdictionary alloc] initwithobjectsandkeys: avvideocodecjpeg, avvideocodeckey, nil]; [newstillimageoutput setoutputsettings:outputsettings]; [outputsettings release]; // create session (use default avcapturesessionpresethigh) avcapturesession *newcapturesession = [[avcapturesession alloc] init]; // add inputs , output capture session if ([newcapturesession canaddinput:newvideoinput]) { [newcapturesession addinput:newvideoinput]; } if ([newcapturesession canaddinput:newaudioinput]) { [newcapturesession addinput:newaudioinput]; } if ([newcapturesession canaddoutput:newstillimageoutput]) { [newcapturesession addoutput:newstillimageoutput]; } [self setstillimageoutput:newstillimageoutput]; [self setvideoinput:newvideoinput]; [self setaudioinput:newaudioinput]; [self setsession:newcapturesession]; [newstillimageoutput release]; [newvideoinput release]; [newaudioinput release]; [newcapturesession release]; // set movie file output nsurl *outputfileurl = [self tempfileurl]; avcamrecorder *newrecorder = [[avcamrecorder alloc] initwithsession:[self session] outputfileurl:outputfileurl]; [newrecorder setdelegate:self]; // send error delegate if video recording unavailable if (![newrecorder recordsvideo] && [newrecorder recordsaudio]) { nsstring *localizeddescription = nslocalizedstring(@"video recording unavailable", @"video recording unavailable description"); nsstring *localizedfailurereason = nslocalizedstring(@"movies recorded on device contain audio. accessible through itunes file sharing.", @"video recording unavailable failure reason"); nsdictionary *errordict = [nsdictionary dictionarywithobjectsandkeys: localizeddescription, nslocalizeddescriptionkey, localizedfailurereason, nslocalizedfailurereasonerrorkey, nil]; nserror *novideoerror = [nserror errorwithdomain:@"avcam" code:0 userinfo:errordict]; if ([[self delegate] respondstoselector:@selector(capturemanager:didfailwitherror:)]) { [[self delegate] capturemanager:self didfailwitherror:novideoerror]; } } [self setrecorder:newrecorder]; [newrecorder release]; success = yes; return success; }
Comments
Post a Comment