0

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Unfortunately the Java tag was missing when I voted to close, so the dupehammer didn't work. However, it really is a duplicate of that question - it has nothing to do with the Google APIs. – Jon Skeet Jan 27 '18 at 08:07
  • In future, please be much more specific than "its not working" - what steps have you taken to diagnose the problem? What happens if you step through the code in the debugger? Have you tried to remove the text to speech API from the problem by just logging where it *would* have called the API? (If you'd stepped through, you'd have seen that the problem was in the condition evaluation.) – Jon Skeet Jan 27 '18 at 08:08
  • hello, the app it's working, what i want to do its taking the text and compare them exemple : If text equals to: I love you. I want to give a message in a Toast saying. – DoctorDroid Haiti Feb 09 '18 at 02:51
  • Please read the linked duplicate. – Jon Skeet Feb 09 '18 at 06:22

0 Answers0