Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Lincoln Cole
Published

Animal Sounds

A fun game for little kids where you tap the buttons to hear animal sounds and then guess which animal it is!

IntermediateProtip12 hours1,579

Things used in this project

Hardware components

Amazon Echo
Amazon Alexa Amazon Echo
×1

Story

Read more

Schematics

No circuit diagram needed!

I don't have a circuit diagram to show because the application exists purely in code and is available on Alexa devices.

Code

InputHandler

Java
This is my input handler that keeps my buttons active. I keep them live for a minute and then prompt the user that it is still active. They can press any button, and I save the buttons in memory in order of when they were pressed. With this, I don't have to have the button 'wake up' action that is usually recommended to find out which buttons exist in the roll call, but rather I can accept any button being activated at any time with a button press AND register the actual event as a unique animal sound based on a pre-set random generation.
  public static StartInputHandlerDirective buildSingleRecognizerDirective(
      HandlerInput input) {
    Map<String, Recognizer> recognizers = new HashMap<>();
    Recognizer allPressed = PatternRecognizer.builder()
        .withAnchor(
            PatternRecognizerAnchorType.START)
        .withFuzzy(true)
        .withPattern(Arrays.asList(Pattern.builder()
            .withAction(
                InputEventActionType.DOWN)
            .build()))
        .build();
    recognizers.put("all pressed", allPressed);
    Map<String, Event> events = new HashMap<>();
    Event completeEvent = Event.builder()
        .addMeetsItem("all pressed")
        .withShouldEndInputHandler(true)
        .withReports(EventReportingType.MATCHES)
        .build();
    Event failedEvent = Event.builder()
        .addMeetsItem("timed out")
        .withShouldEndInputHandler(true)
        .withReports(EventReportingType.MATCHES)
        .build();
    events.put("complete", completeEvent);
    events.put("failed", failedEvent);
    setOriginatingId(input, input.getRequestEnvelope()
        .getRequest()
        .getRequestId());
    return StartInputHandlerDirective.builder()
        .withTimeout(60000L)
        .withEvents(events)
        .withRecognizers(recognizers)
        .build();
  }

Credits

Lincoln Cole

Lincoln Cole

4 projects • 3 followers
An author and Alexa Developer.

Comments