package org.uoc.pac3.DroidEye;


import java.util.Locale;

import org.uoc.pac3.DroidEye.R;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
 
public class tts_control extends Activity implements
        TextToSpeech.OnInitListener {
 
    private TextToSpeech tts;

 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.droideye_surface_view);
 
        
        
        Intent checkTTSIntent = new Intent();
        checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
        startActivityForResult(checkTTSIntent, 0);
 

    }
 
    @Override
    public void onDestroy() {
        //shutdown tts!
        if (tts != null) {
            tts.stop();
            tts.shutdown();
        }
        super.onDestroy();
    }
 
    @Override
    public void onInit(int status) {
 
    	//Comprovem que s'ha iniciat correctament
        if (status == TextToSpeech.SUCCESS) {
        	tts.setLanguage(Locale.US);
            	
        	tts.speak("This is Droid Eyes, system used to recognize the money that you have on a surface.", TextToSpeech.QUEUE_FLUSH, null);
            //mTTS.speak("Hello Marc, Gisela, Elo, Aleix, how are you.", TextToSpeech.QUEUE_FLUSH, null);
        }
        else if (status == TextToSpeech.ERROR) {
        		// no funciona...
        }
 
    }
 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 0) {
            if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
            {
            	tts = new TextToSpeech(this, this);
            	
            }
            else 
            {
                //no data - install it now
                Intent installTTSIntent = new Intent();
                installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installTTSIntent);
            }
        }
    }
        
    public void speakOut(String text) {
 
        tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
    }
}
