谷歌Vison文本识别

时间:2018-01-27 08:04:43

标签: java text speech vision

我在codelabs开发者google上关注Google vision api的教程,它对我来说很好 有一种名为 ONTAP 的方法,当用户clic相机屏幕TexttoSpeech时,大声说出文字。 这是方法:

 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;
    }

现在我想做的是当相机检测到句子字符串时:我爱你我想让它在TOAST中行动,例如说: 确定已检测到此句话。 我试过这不起作用:

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;
    }

请有人帮助我。谢谢你。

0 个答案:

没有答案