[Solved] How do I add a new Input to InputManager?

So I have a new Input Speechinput it has SpeechListener, and SpeechTrigger all this is fine and dandy but I need to update my SpeechInput in the InputManager this would be great if we had something like…

public class InputManager implements RawInputListener {
	
	// Fields...
	
	public final ArrayList<Input> inputs = new ArrayList<Inputs>();
	
	public InputManager(MouseInput mouse, KeyInput keys. Input... inputs) {
		if (keys == null || mouse == null) {
            throw new IllegalArgumentException("Mouse or keyboard cannot be null");
        }
		
		this.inputs.add(keys);
		this.inputs.add(mouse);
		
		for(Input input : inputs) {
			inputs.initialize(this);
			this.inputs.add(input);
		}
		
		firstTime = keys.getInputTimeNanos();
	}
	
	// Methods...
	
	private void processQueue() {
		int queueSize = inputQueue.size();
		RawInputListener[] array = rawListeners.getArray(); 
		
		for (RawInputListener listener : array) {
			listener.beginInput();
			
			for (int j = 0; j < queueSize; j++) {
				InputEvent event = inputQueue.get(j);
				if (event.isConsumed()) {
					continue;
				}
				for(Input input : inputs) {
					if(inputs.onEvent(event)) {
						break;
					}
				}
			}
			listener.endInput();
		}
		
        for (int i = 0; i < queueSize; i++) {
			InputEvent event = inputQueue.get(i);
			if (event.isConsumed()) {
				continue;
			}
			for(Input input : inputs) {
				if(inputs.onQueuedEvent(event)) {
					event.setConsumed();
					break;
				}
			}
        }
		
        inputQueue.clear();
    }
	
	// Methods...
	
}

and Input like this

public interface Input {
	
	// Methods...
	
	public void initialize(InputManager inputManager);
	
	public void onEvent(Event event);
	
	public void onQueuedEvent(Event event);
	
	// Methods...
	
}

I know the code above is half baked at beast you but you see what I am saying.

Then I could just new up an input manager with all the inputs I want with the required Key and Mouse Inputs… but alas we don’t have something like this so what is advised?

FYI: What I have working now uses CMU Sphinx and Android.speech. It is rigged in there horribly.

1 Like

Why do you need to put these two things together? That’s the part I don’t understand.

If it’s just life cycle management… then use an app state.

Well I am glad you asked. My thought is that speech recognition is becoming more popular and is a standard input on most devices now a days, so why not have it in the input manager? Also the design proposed would allow for a more flexible input manager.

I do see your point and in my game I am currently using an app state.

So I assume use BaseAppState do not add your own input is the answers…

Works for me thank you @pspeed

Yeah, I mean… for one thing, speech input seems completely different than regular “things I’m holding in my hands” input.

For another, if you expanded your pseudo code to actually be working code you’d see that it’s much more complicated than that… and for little purpose, really.

Speech input is not at all like an analog input. It’s barely like a button input. (What’s the pressed versus released on speech?)

So it makes sense to me to do it separately.

A cool idea! (with a lot of potential)

I remember 10 years ago when I worked at a VR lab - it had speech recognition in a Unix-based VR installation. Since they had to deal with 3D gestures as VR input, the “audio gestures” seemed to be the next logical step - so they implemented it too. :chimpanzee_smile:

I would feed my ingame console with it (“Drop 10 enemies in front of me!”, “Restart level!”, “Plus 10 velocity!”, “Next!”, “Previous!”, “Flycam!”, “Chasecam!”, “Wireframe!”, “Screenshot!”, …).

In a game it would be cool too: “Computer, show me the shortest way to ten forward, to shuttle bay and then to the sick bay.” - ehm - “now!” :chimpanzee_closedlaugh:

If any of you have/know a working speech recognition library (that works for more than just windows, and has a license allowing to use it in a game), I would be very interested.
As my ship computer can already speak acceptably, this would be great.

Even if it would just be capable of detecting a list of like 30 predefined words it would be pretty awesome.

Theres actually a plugin for that in the SDK

I think I mentioned it but I am using a combination of android.speech, J.A.R.V.I.S, CMU Sphinx, and Pocket Sphinx

Basically to fit my needs I need a Speech Recognition engine not a STT engine so I am using Google’s web and android STT to text to help train my CMU Sphinx dictionary until it becomes more mature. Until then users will need to click or touch a button before they start talking. but I am not focusing on that until I actually get an alpha version out there.

EDIT
To answer your question that is exsactly what CMU Sphinx and Pocket Sphinx are for.

1 Like