An array detects only part of the input word instead of the entire word

I have a problem in my Android application, this application uses voice recognition and Google TTS. It looks like a SIRI client. As you can see here when the user says a word in an array:

String[] g = { "hallo", "heey", "hoi", "hey", "he", "hee", "hay" }; for (String strings : g) { if (mostLikelyThingHeard.contains(strings)) { String[] array = { "leuk dat je er bent", "heeyy" }; String randomStr = array[new Random() .nextInt(array.length)]; tts.speak(randomStr, TextToSpeech.QUEUE_FLUSH, null); return; } } String[] f = { "haha", "hah", "ha" }; for (String strings : f) { if (mostLikelyThingHeard.contains(strings)) { String[] array = { "haha leuk grapje", "hiehaho" }; String randomStr = array[new Random() .nextInt(array.length)]; tts.speak(randomStr, TextToSpeech.QUEUE_FLUSH, null); return; } } 

Everything works fine, but when the user says "hallo", he first discovers the first two characters "ha". What is mentioned in the String 'f' array. So it’s annoying, the whole word is not found, but only a part of it.

When I replace two arrays of strings as follows:

 String[] f = { "haha", "hah", "ha" }; for (String strings : f) { if (mostLikelyThingHeard.contains(strings)) { String[] array = { "haha leuk grapje", "hiehaho" }; String randomStr = array[new Random() .nextInt(array.length)]; tts.speak(randomStr, TextToSpeech.QUEUE_FLUSH, null); return; } } String[] g = { "hallo", "heey", "hoi", "hey", "he", "hee", "hay" }; for (String strings : g) { if (mostLikelyThingHeard.contains(strings)) { String[] array = { "leuk dat je er bent", "heeyy" }; String randomStr = array[new Random() .nextInt(array.length)]; tts.speak(randomStr, TextToSpeech.QUEUE_FLUSH, null); return; } } 

Then he discovers "hallo" first instead of "ha"

But if I create more than 100 arrays, it will be annoying, since I can let java use the best matching word from the array instead of the part?

I know this is hard to understand, but if you guys don't understand what you see my source here: http://github.com/gi097/PWS

EDIT:

When i change

 contains 

to

 equals 

I am fixing this problem, but now I have a new one:

If I create an array like:

 "I am" 

When the user says: β€œI am Giovanni”, we have a problem that the β€œI” is no longer detected due to peers ....

EDIT2

It can be fixed. I think that with mostLikelythingHeard "I Giovanni" splits into "I" "I" "Giovanni", but how?

+5
source share
1 answer

Instead

 mostLikelyThingHeard.contains(strings) 

Using:

 Arrays.sort(g); int index = Arrays.binarySearch(g, mostLikelyThingHeard); if (index >= 0) { System.out.println("I heard it properly and its ", g[index]); } 

Contains a String subsequence check, as indicated here . So if your line was "hallo", then "Hallo".contains("ha") searches for ha in hallo and yes, this is hail and therefore your problem.

0
source

Source: https://habr.com/ru/post/1208657/


All Articles