RSS

Monthly Archives: February 2013

Android App >> Tukumbuke (Swahili for Let’s not forget)

581252_558653964152688_1363415599_n (1)
The years 2007 and 2008 were the worst years Kenya has ever had. It saw neighbors rise against each other and doing all sorts of inhumane things, destroying property and even killing each other. Now, five years later, we have a chance to choose our leaders again and every Kenyan has a choice to make about which path we gonna head.
Tukumbuke is an app I built at the Apps4Election event. We were in a team of about 8 brilliant guys. With tukumbuke we want to remind Kenyans of what happened when we let ethnicity come in between us. We wanted to also highlight the injustices done to our fellow Kenyans and give a voice to the Post Election Violence victims. There is a web version though its not yet up, a facebook page and a twitter handle.


Get it on Google Play

Below are the screenshots:

Screenshot_2013-02-16-12-41-11 Screenshot_2013-02-16-12-48-35 Screenshot_2013-02-17-12-55-01 Screenshot_2013-02-17-12-55-39 Screenshot_2013-02-18-06-22-44 Screenshot_2013-02-19-21-43-14 Screenshot_2013-02-19-21-42-38 Screenshot_2013-02-19-15-37-56 Screenshot_2013-02-16-12-34-36

Advertisements
 
Leave a comment

Posted by on February 20, 2013 in Uncategorized

 

My Apps << Translatr

Screenshot_2013-02-06-10-43-23

Screenshot_2013-02-06-12-44-18

 
13 Comments

Posted by on February 6, 2013 in Uncategorized

 

Android Tutorials << Building a Language Translator App with Text To Speech feature

One of my friends is going abroad – to Germany. I thought I’d make her an app that would let her enter what she wants to say in English translate it to German then speak it out.

Here goes:
I am going to be using the Bing Translate API – really cool coz they give u like two million queries, that’s a lot (unfortunately Google translate API isnt free).
First, download this java library. Place this in your libs folder.

We need the Client Id and Client username from the Microsoft MarkerPlace. Here are the instructions on how to get this.
 

I am gonna build this:
Screenshot_2013-02-05-15-07-38

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/etUserText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="31dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/tvTranslatedText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/etUserText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="168dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/bTranslate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/etUserText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:text="Translate" />

    <Button
        android:id="@+id/bSpeak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvTranslatedText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="46dp"
        android:text="Speak" />

</RelativeLayout>

To get translated text do this:

public String translate(String text) throws Exception{
	// Set the Client ID / Client Secret once per JVM. It is set statically and applies to all services
       Translate.setClientId("CLIENT USERNAME");
       Translate.setClientSecret("CLIENT SECRET");
       
       String translatedText = "";
       
       // English AUTO_DETECT -> gERMAN Change this if u wanna other languages
       translatedText = Translate.execute(text,Language.GERMAN);
       return translatedText;
   }

The Text-To-Speech bit:

public class MainActivity extends Activity implements OnInitListener {

	private TextToSpeech tts;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tts = new TextToSpeech(this, this);
        speakOut("Ich"); //This is how you will get the phone to  speak    
}

@Override
public void onInit(int status) {
	// TODO Auto-generated method stub
	if (status == TextToSpeech.SUCCESS) {
		 
        int result = tts.setLanguage(Locale.GERMAN);

        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        } else {
            
            //speakOut("Ich");
        }

    } else {
        Log.e("TTS", "Initilization Failed!");
    }
}
   
private void speakOut(String text) {
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}

And the complete code:

package com.gilo.translatr;

import java.util.Locale;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;

public class MainActivity extends Activity implements OnInitListener {

	private TextToSpeech tts;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        tts = new TextToSpeech(this, this);
        ((Button) findViewById(R.id.bSpeak)).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				speakOut(((TextView) findViewById(R.id.tvTranslatedText)).getText().toString());
			}
		});
        
        ((Button) findViewById(R.id.bTranslate)).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				
				
				class bgStuff extends AsyncTask<Void, Void, Void>{
					
					String translatedText = "";
					@Override
					protected Void doInBackground(Void... params) {
						// TODO Auto-generated method stub
						try {
							String text = ((EditText) findViewById(R.id.etUserText)).getText().toString();
							translatedText = translate(text);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
							translatedText = e.toString();
						}
						
						return null;
					}

					@Override
					protected void onPostExecute(Void result) {
						// TODO Auto-generated method stub
						((TextView) findViewById(R.id.tvTranslatedText)).setText(translatedText);
						super.onPostExecute(result);
					}
					
				}
				
				new bgStuff().execute();
			}
		});
    }

   public String translate(String text) throws Exception{
	  
	   
	// Set the Client ID / Client Secret once per JVM. It is set statically and applies to all services
       Translate.setClientId("CLIENT ID"); //Change this
       Translate.setClientSecret("CLIENT SECRET"); //change
       
       
       String translatedText = "";
       
       translatedText = Translate.execute(text,Language.GERMAN);
	   
       return translatedText;
   }

@Override
public void onInit(int status) {
	// TODO Auto-generated method stub
	if (status == TextToSpeech.SUCCESS) {
		 
        int result = tts.setLanguage(Locale.GERMAN);

        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        } else {
            
            //speakOut("Ich");
        }

    } else {
        Log.e("TTS", "Initilization Failed!");
    }
}
   
private void speakOut(String text) {
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
   
}

There is a lot you can do, but I am feeling to lazy. Hope you learnt something.

[UPDATE] Check out the App here, I just gave it a better look but its still more or less the same thing described above.
 

 
58 Comments

Posted by on February 5, 2013 in Uncategorized

 

App

 

 
Screenshot_2013-02-04-08-22-52

Screenshot_2013-02-04-08-23-00

Screenshot_2013-02-04-08-23-09

Screenshot_2013-02-04-14-22-04

 
Leave a comment

Posted by on February 4, 2013 in Uncategorized