I followed tutorial on codelabs developer google for Google vision api, it's worked fine for me There is a method called ONTAP, when the user clic the camera screen TexttoSpeech, speak the text loud. Here is the method:
private boolean onTap(float rawX, float rawY) {
// TODO: Speak the text when the user taps on screen.
OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
TextBlock text = null;
if (graphic != null) {
text = graphic.getTextBlock();
if (text != null && text.getValue() != null) {
Log.d(TAG, "text data is being spoken! " + text.getValue());
// Speak the string.
tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
}
else {
Log.d(TAG, "text data is null");
}
}
else {
Log.d(TAG,"no text detected");
}
return text != null;
}
NOW what i want to do is when the camera detect the sentence string: I LOVE YOU I want it to make in action in a TOAST for example to say: Ok this sentence has been detected. I tried this its not working:
private boolean onTap(float rawX, float rawY) {
// TODO: Speak the text when the user taps on screen.
OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY);
TextBlock text = null;
if (graphic != null) {
text = graphic.getTextBlock();
if (text != null && text.getValue() != null) {
Log.d(TAG, "text data is being spoken! " + text.getValue());
// Speak the string.
tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT");
}
else if (text.getValue()=="I love you"){
// Speak the string.
Toast.makeText(this, "Ok this sentence has been detected", Toast.LENGTH_LONG).show();
}
else {
Log.d(TAG, "text data is null");
}
}
else {
Log.d(TAG,"no text detected");
}
return text != null;
}
Please somebody helps me. Thanks you.