We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2265

Summary: Voice to text feature on Android repeats some text via SDL_TEXTINPUT
Product: SDL Reporter: philhassey <phil>
Component: eventsAssignee: Sylvain <sylvain.becker>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq, icculus, phil
Version: 2.0.1   
Hardware: ARM   
OS: Android (All)   
Attachments: patch

Description philhassey 2013-11-23 14:38:00 UTC
Overview:

Voice to text feature on Android repeats some text via SDL_TEXTINPUT. 

Steps to Reproduce:

- Bring up the keyboard
- Press the dictation button
- Say something like "math is hard"

Actual Results:

- I get three SDL_TEXTINPUT events. 
- "math"
- " is"
- "math is hard"

(Thus my program gets the text: "math ismath is hard")

Expected Results:

- I get three SDL_TEXTINPUT events.
- "math"
- " is"
- " hard"

(So my program should get the text: "math is hard")

Build Date & Hardware:

I'm using a Motorola Xoom with Android 4.1.2
Comment 1 Ryan C. Gordon 2015-02-18 20:37:38 UTC
Gabriel, is this something you can reproduce? If it's an easy fix, I'd like to get it into 2.0.4.

--ryan.
Comment 2 Ryan C. Gordon 2015-02-19 05:22:22 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 3 Sylvain 2017-08-23 20:46:56 UTC
I give a try on a different version (Android 5.1.1) and it seems to work correctly: one SDL_TEXTINPUT event for the whole sentence.


But, I noticed the variable "newCursorPosition" is not used.
https://hg.libsdl.org/SDL/file/4276937a9792/android-project/src/org/libsdl/app/SDLActivity.java#l1664
https://hg.libsdl.org/SDL/file/6120f75935f9/src/core/android/SDL_android.c#l554

Android doc: 
https://developer.android.com/reference/android/view/inputmethod/InputConnection.html#commitText(java.lang.CharSequence,%20int)


Maybe there could be some corner case where we should use the "newCursorPosition" ?
Comment 4 Sylvain 2017-08-25 20:21:51 UTC
On an Android Nexus10, with Android 4.2.2, I have reproduced the issue.

Saying : "1 2 3", I got the input : 

commitText:__12__  newCursorPosition=1
deleteSurroundingText beforeLength=1  afterLength=0
commitText:__ __  newCursorPosition=1
commitText:__2__  newCursorPosition=1
commitText:__ 3__  newCursorPosition=1
deleteSurroundingText beforeLength=5  afterLength=0
commitText:__1 2 3__  newCursorPosition=1


I think you can have several SDL_TEXTINPUT events (eg redundant commitText()), but in between, you have also a few "backspaces" (deleteSurroundingText()).

I you sum up all commiText()s and deleteSurroundinText()s, you have the correct sentence in the end.


But, currently, I think deleteSurroundinText() is broken because it would only send 1 backspace whereas 5 backspaces are need in the example.
Also, it uses "sendKeyEvent()" which do both a commitText() and a onNativeKeyDown(). (backspace would be duplicated).
Comment 5 Sylvain 2017-08-26 20:26:05 UTC
Created attachment 2895 [details]
patch

Small patch for this issue. I tested it and it seems to work.

- it can send several backspaces (instead of only 1).
- it calls directly "sendKeyEvent()" instead of "super.sendKeyEvent()".
  otherwise, it would go through the android internals, calling again "onKey()".
  and then the "backspace" would arrive after the next "commitText()".
Comment 6 Sam Lantinga 2017-08-28 01:37:20 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/323fc605104f