teaching machines

Homework 1 – wettstaj

September 30, 2011 by . Filed under cs491 mobile, fall 2011, postmortems.

WHO’S THAT POKEMON?

That’s right boys and girl, the moment has finally come. Finally an app that lets you guess and memorize all the names of your favorite pokemon. Actually, its not that great yet. But for what it is i think it works pretty slick and simple and if off to a good start.

The app starts up and does a text to speech telling you that your in the app and that you need to press play to begin. I will explain how this is done later. I wasn’t so focused on the UI of the main page because there inst much there to start with.

once you press play the game opens up and has a Edit text at the bottom of the screen. Just enter the correct name of the Pokemon that appear and press submit. If your right then the image will switch and a toast will pop up saying that you were correct. If you are wrong then a toast will pop up and tell you to try again.

I dont really like using different activities when they are not needed so the image is just changed on the screen along with a string to compare to what is in the text field. The img that shows up is completely random but could easily be implemented in chronological order or with a scroll down selector.

                         

You obviously cant see it but i have a text to speech that just welcomes you into the game. Originally, i wanted this to be a speech to text function but realized that it would be very difficult to test without and android device. And the way i was trying to do it it seemed like you needed to be connect to the internet because it would work off of an online database of words somewhere. Anyway, it took a lot of time from me on this project which is why i think it looks so plain.

So back to the text to speech:

first implement

public class Main extends Activity implements TextToSpeech.OnInitListener {

add into the main method to set up the text to speech

mTts = new TextToSpeech(this, this);
sayHello();

this is in case you know…something bad happens that it is stopped.

@Override
    public void onDestroy() {
        // Don’t forget to shutdown!
        if (mTts != null) {
            mTts.stop();
            mTts.shutdown();
        }

        super.onDestroy();
    }
this is just a way to add more phrases and randomize which one with be said

    private static final Random RANDOM = new Random();
    private static final String[] HELLOS = {
      “Welcome to the: Who’s that poke mon Android app! Press play to begin.”
    };

a method to call to tell the speech what to say and when

    private void sayHello() {
        int helloLength = HELLOS.length;
        String hello = HELLOS[RANDOM.nextInt(helloLength)];
        mTts.speak(hello,
            TextToSpeech.QUEUE_FLUSH,  null);
    }

tells it what language and what speech is supported, if it is not supported it will not work, duh.
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            int result = mTts.setLanguage(Locale.US);
            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Log.e(TAG, “Language is not available.”);
            } else {
                sayHello();
            }
        } else {
            Log.e(TAG, “Could not initialize TextToSpeech.”);
        }
    }