Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Samsung S8 #73

Open
PersistantStudio opened this issue Apr 15, 2022 · 18 comments
Open

Error on Samsung S8 #73

PersistantStudio opened this issue Apr 15, 2022 · 18 comments

Comments

@PersistantStudio
Copy link

Hi, recently it seems that the plugin encounter difficulties to run on some devices, on android 8/9 , ( samsung S8), while still working correctly on a Pixel 6.

On the S8 I receive a lot of RMS Changed callbacks ( that seems to be related to the sound level) and then the application crash with an IndexOutOfBoundException in the onPartialResults Handler. For some reason it seems that the StringArrayList is empty, leading to the instruction text.get(0) to crash.

I'm mostly suprised by what I'm interpreting to be a sudden incompatibility, as the application was properly working precedently.

Even weirder, by trying to create the minimal project to try to reduce the prism, I narrow the condition of reproduction to be directly related by the change in the the custom manifest files as I only experience this crash when I deactivate the show popup option, as the method StartRecording access the MainActivity. The Vocal recognition seems to be working with no custom manifest and the option Show Popup set as true.

@kayabilgehan
Copy link

We have same problem. Can you share the solution with us, if you fixed the issue?

@hojjatabdollahi
Copy link

We are having the same issue. The app crashes if you try to hide the pop up. But it works fine if you show the pop up (which covers the whole app).

Did anybody come up with any solutions to this?

@PersistantStudio
Copy link
Author

PersistantStudio commented Apr 19, 2022

We were able to fix the problem, wich is pretty simple to adress
Just adding null checks ans size check before accessing the entry 0 in the array in OnResults & OnPartialResults.

   public void onResults(Bundle results) {
            ArrayList<String> text = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            if(text != null && text.size() >0) {
            UnityPlayer.UnitySendMessage("SpeechToText", "onResults", text.get(0));
            }
        }
        @Override
        public void onPartialResults(Bundle partialResults) {
            ArrayList<String> text = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            if(text != null && text.size() >0) {
            UnityPlayer.UnitySendMessage("SpeechToText", "onPartialResults", text.get(0));
            }
        }`
```
The hardest part was in fact to build the plugin thas is really outdated. It's way easier to start from scratch in fact. 

> 

@hojjatabdollahi
Copy link

hojjatabdollahi commented Apr 19, 2022

@PersistantStudio , Thank you.

It took us a whole day to get android studio to compile this. We had already added a check on text.size() but adding the check for null fixed the crash. That being said, our app is now stuck, which I assume is because if the if is not true (the text is empty) nothing is sent to Unity. We are working on fixing this by sending an empty string. Maybe that works!!

Thanks again.

@PersistantStudio
Copy link
Author

I think we encountered the same issue.The call are made by name on gameobject on the Java side, so the name in Unity3D need to match the one defined in the Java plugin. The code on this repo contains an error in the way the game object is named in Unity : It is actually named TextToSpeech instead of SpeechToText when you use the lazy instanciation. Correcting this error will fix the issue of not getting any callbacks.

@kayabilgehan
Copy link

kayabilgehan commented Apr 29, 2022

We fixed the issue by storing the text created in "onPartialResults" in a variable and if the data comes from "onResults" is null, than we use the stored text data.
Code:

private Intent intent;

String partialStringResult = ""; //variable to store text from onPartialResults

@OverRide
public void onCreate(Bundle savedInstanceState) {

.
.
.

@OverRide
public void onResults(Bundle results) {
ArrayList text = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if(text != null && text.size() > 0) {
UnityPlayer.UnitySendMessage("SpeechToText", "onResults", text.get(0));
}
else if(partialStringResult != null && !partialStringResult.equals("")) {
UnityPlayer.UnitySendMessage("SpeechToText", "onResults", partialStringResult); //send unity the stored string
}

}
@OverRide
public void onPartialResults(Bundle partialResults) {
ArrayList text = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if(text != null && text.size() > 0) {
partialStringResult = text.get(0); //store data to use it if needed
UnityPlayer.UnitySendMessage("SpeechToText", "onPartialResults", text.get(0));
}
}

Edit:
After these changes in Java I made changes below too in build.gradle in app level.

task deleteOldJar(type: Delete) {
delete 'release/SpeechToTextPlugin.jar'
}

//task to export content as jar
task exportJar(type: Copy) {
from('build/intermediates/compile_library_classes_jar/release/')
into('release/')
include('classes.jar')
rename('classes.jar', 'SpeechToTextPlugin.jar')
}

exportJar.dependsOn(deleteOldJar, build)

@medinags
Copy link

@kayabilgehan Thanks for your solution, but my question is where should I implement this solution, in Unity?

@PersistantStudio
Copy link
Author

Nope the modifications needs to be made in the java project of the plugin.

@kayabilgehan
Copy link

@medinags you have to make this changes in android studio with java like @PersistantStudio said.

@takijemai
Copy link

hello, sorry i have the same question, i m new with unity and i do this task, where i can found the java project of the plugin please?

@pedropll98
Copy link

I have the same problem and when I installed Android Studio it told me that I need HAXM to work, but my computer does not meet the requirements. What can I do to edit the plugin?

@pedropll98
Copy link

Can anyone share the plugin already fixed?

@Aneeb151
Copy link

Aneeb151 commented Jul 8, 2022

SpeechToTextPlugin.jar.zip
Anybody suffering from this problem can first update their files from the repository to latest (specially SpeechToText.cs and TextToSpeech.cs) and then replace their jar file from "Assets/Plugins/Android/SpeechToTextPlugin.jar". I have followed and updated @kayabilgehan solution as it had a type casting error and compiled the files from android studio.
Thanks @PersistantStudio and @kayabilgehan for your efforts :)

@takijemai
Copy link

SpeechToTextPlugin.jar.zip Anybody suffering from this problem can first update their files from the repository to latest (specially SpeechToText.cs and TextToSpeech.cs) and then replace their jar file from "Assets/Plugins/Android/SpeechToTextPlugin.jar". I have followed and updated @kayabilgehan solution as it had a type casting error and compiled the files from android studio. Thanks @PersistantStudio and @kayabilgehan for your efforts :)

hello ,thank you for the reply but even i change the jar file and update the two files of textspeech and speechtotext it's does'nt work

@Sukanta-Patra
Copy link

SpeechToTextPlugin.jar.zip Anybody suffering from this problem can first update their files from the repository to latest (specially SpeechToText.cs and TextToSpeech.cs) and then replace their jar file from "Assets/Plugins/Android/SpeechToTextPlugin.jar". I have followed and updated @kayabilgehan solution as it had a type casting error and compiled the files from android studio. Thanks @PersistantStudio and @kayabilgehan for your efforts :)

This fixed the issue. Thank you so much man! <3

@GSJuan
Copy link

GSJuan commented Jan 18, 2023

SpeechToTextPlugin.jar.zip Anybody suffering from this problem can first update their files from the repository to latest (specially SpeechToText.cs and TextToSpeech.cs) and then replace their jar file from "Assets/Plugins/Android/SpeechToTextPlugin.jar". I have followed and updated @kayabilgehan solution as it had a type casting error and compiled the files from android studio. Thanks @PersistantStudio and @kayabilgehan for your efforts :)

Saved my life @Aneeb151. Thank you very much!

@usamaqh
Copy link

usamaqh commented Jan 20, 2023

SpeechToTextPlugin.jar.zip Anybody suffering from this problem can first update their files from the repository to latest (specially SpeechToText.cs and TextToSpeech.cs) and then replace their jar file from "Assets/Plugins/Android/SpeechToTextPlugin.jar". I have followed and updated @kayabilgehan solution as it had a type casting error and compiled the files from android studio. Thanks @PersistantStudio and @kayabilgehan for your efforts :)

Thanks a lot brother!

@Blindsp0t-creative
Copy link

SpeechToTextPlugin.jar.zip Anybody suffering from this problem can first update their files from the repository to latest (specially SpeechToText.cs and TextToSpeech.cs) and then replace their jar file from "Assets/Plugins/Android/SpeechToTextPlugin.jar". I have followed and updated @kayabilgehan solution as it had a type casting error and compiled the files from android studio. Thanks @PersistantStudio and @kayabilgehan for your efforts :)

Thank you so much for this !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests