问题
I need to record several thousand short soundbites of my own speech (I'm training an acoustic model for a speech recognition engine)
So for each one, a line of text presents itself on the screen and I have to speak it, and capture the audio into a .WAV
I found a sample project for recording the audio; now I am trying to figure out how to do keyboard input.
I would like to push the SPACEBAR down to start recording and release it to terminate the recording.
Can anyone get me started? ( an example would be ideal! )
Sorry, this is probably really really basic -- I haven't done any coding in OS X before (though I have done a lot of iOS work so I am no stranger to Xcode and some of the frameworks)
回答1:
If you create a basic Cocoa application, you can use the following methods of NSResponder
, of which NSView
is a subclass, to capture your desired key up/down events:
-(void)keyDown:(NSEvent*)event;
-(void)keyUp:(NSEvent*)event;
Use [event keyCode]
to get the key pressed.
来源:https://stackoverflow.com/questions/8198109/osx-detect-spacebar-down-and-up-events