mardi 29 juin 2021

In Android Studio, I have used a speech to text. I want it to verify the word that the user speaks, but something is wrong. Help is appreciated

My project in Android Studio is written in Java. I have implemented a mic button that when clicked, prompts the user to a (Google) speech to text that will display the user's words in an XML TextView. I have a Button (submit) that the user should click after speaking, so it can verify the word that the user spoke. I would like it to verify if the user has spoken the word 'office', and in another TextView, display either 'Correct' or 'Incorrect'. I have created code for this, but no matter what word I speak, even 'office', it says it is incorrect. I used an if else statement and a setText for this. If this is relevant, I am testing on a phone, not an emulator because the emulator wouldn't allow speech to text. I would really appreciate any assistance with this as I have been struggling to find help for a while now.

 button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                String wordText = (String) word.getText();
                if (wordText == "office") {
                    responseText = "Nice job, that is correct!";

                } else {
                    responseText = "Sorry, that is incorrect.";


                }
                response.setText(responseText);


            }
        });


    }

The button, when clicked, should determine whether the user has spoken the word 'office' or not. The TextView 'word' displays the word that the user has spoken in the mic. The String 'responseText' is the response for whether the user has spoken the right word or not. The TextView 'response' is set to the text of 'responseText' to show either 'correct' or 'incorrect'.

Aucun commentaire:

Enregistrer un commentaire