I'm trying to get TextToSpeech to speak alphanumeric references in the Android emulator. If I have a string such as "31NAA123", then I insert spaces between all the characters and then submit it to the speak method. It copes OK with most letters but stumbles on the 'A's, they come out as barely audible very short "ah"s, almost as short as clicks. I've tried replaceAll("A", "AY") which comes out as "ay, why". I've tried most speech rates down to 0.3f - nothing works. I'm using a UK locale to give a British accent. I'd be grateful if anyone has any useful suggestions.
(I suspect 'i' will give similar problems, 'o' seems to be OK)
Have you tried inserting multiple points after the letters? Seems to work pretty well for me:
String s = "a.. b.. c..";
Or even slower:
String s = "a... b... c...";
Related
I am PhoneNumberUtil to see phone numbers i enter into a text view and then send them a message. However it does not work as my Numbers are Formated with a '+44 ...' whereas PhoneNumberUtils needs numbers to be written like '44...'. Does anyone know how i can fix this?
If I am understanding your issue correctly, it sounds like you want to strip just the numbers from a string to leave an unformatted number for the formatter to work with.
My app needs to display numeric ranges in a TextView, such as "34-93". TalkBack is reading this as "thirty-four minus ninety-three". I want it to either read "thirty-four dash ninety-three" or "thirty-four to ninety-three" I've tried inserting spaces before and after the dash, as well as using both a hyphen and en-dash, to no avail. In general, though, I have little control over how this string is formatted.
It seems like it should read "dash" if there were some attribute to cause it to read punctuation literally, like accessibilitySpeechPunctuation in iOS.
I have the following idea:
In German we have four extra letters (ä, ö, ü, ß) and I don't know any other language which has these vocals but I think French people with their accents also know this problem. We have a lot of apps in the Google Play store for cities, bus stations, trains and other stuff like that. Now it is really exhausting that we always have to write these letters if we are on the go. It would be much easier to write Munchen (=München [de] = Munich [en]), Osterreich (Österreich [de] = Austria [en]) or something like Uberwasserstrasse (Überwasserstraße [de] = Over-Water-Street [en]). So my question is now:
A lot of apps show suggestions for our just typed word. I think in the code it is something like this:
String current = editText.getText().toString();
db.lookUp(current); // Of course SQL statement
Can we hook this so that Android thinks that we have typed an ä, ö, ü, ß if we write an a, o, u, ss and the system looks for words with one of these vowels and suggests both? Here I do not want to ask for code - I want to discuss if we are able to write a hack or hook for the Android system. Also, root-rights can be assumed with the solution. I'm looking forward to your ideas.
You could do this the other way around, by "normalizing" typed characters into their related non-diacritical versions. You can use the java.Text.Normalizer class for this. A good snippet can be found in this article:
public static String removeAccents(String text) {
return text == null ? null :
Normalizer.normalize(text, Form.NFD)
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
}
When applied to "Münich", this returns "Munich". That way, you can use a simple string comparison using these normalized versions.
This wouldn't work for "ß" though. If that's the only special case, you could handle it separately.
What you are looking for is called accent-insensitive collating sequence. SQLite's COLLATE operator can be used to do such searches, but I learned from another post that there might be bugs you'll need to look out for.
I wanted to know if there is a way to detect if the user's input is in greek charset.
Edit:
Just to be more clear, I need to recognize the language the user types and not the phone's locale. For example, my phone is in English and let's say my keyboard is in Russian, the getDefault() returns "en", but I need to have "ru" at that point.
I do not know if this is available out of the box from android, maybe an approach to detect the string's character codes and see if is in English alphabet or in another. Any points on this?I imagine something like if character belongs to K then is English (where K is the essemble of english characters)
Solution:
Finally I used regular expression to determine if the string is in English.
String pattern = "^[A-Za-z0-9. ]+$";
if (string.matches(pattern)
// is English
else
// is not English
If someone has to propose a better solution I will mark it as answer.
You can use following method instead of pattern matching:
boolean isEnglish = true;
for ( char c : s.toCharArray() ) {
if ( Character.UnicodeBlock.of(c) != Character.UnicodeBlock.BASIC_LATIN ) {
isEnglish = false;
break;
}
}
Locale.getDefault().getLanguage().equals("gr")
In other way:
contains(Charset)
EDIT:
After some more time of browsing, I have come across CharsetDetector and Character Set Detection.
Here you have method detect() but am not sure how best this can be utilized.
As Siva suggests, you can check the user's locale.
In Android, this can be done by using Locale.getDefault(). Although I wouldn't strictly compare it to a 2-letter code, current Android implementation has it being a 2-letter language code, an underscore, and a two-letter country code. Ie., de_US would be German as spoken in the United States.
This is not the way the industry is moving, but its the best-supported pattern as of Java 6. Java 7, once supported by Android should support ISO 639 alpha-3 codes that are more future-proof.
I am trying to modify the SoftKeyboard example (Andriod 3.1 on Moto Xoom) so that I can use an icon on the key and have it output a unicode character when that key is pressed. Specifically I am trying to have it output a beamed eighth note (musical symbol) which is unicode \u266B. Unfortunately I cannot use keyOutputText and keyIcon on the same key in the symbols.xml file which lays out the keys. I need keyIcon because I could not find a way to change the Typeface on the Keyboard Keys to one with that character. I found where I would do it, but its a call to a private method (.setTypeFace) buried in android.jar (KeyboardView if I recall) so I can't.
So I just use an icon to put on the key. This works fine in combination with android:codes, however android:codes will not output my unicode character when I feed it android:codes="\\u266B" which documentation says it should accept. I need android:keyOutputText="\u266B" to get the character to actually output into my EditText. So I can make the key display an icon of my character and the EditText display the character itself, but not the two together. When I try to use the 2 together it compiles and runs just fine, then I hit the shift button on the keyboard to display the symbols and only the numbers 0-9 show up, the rest of the keyboard is just gone. Now error messages or anything, just gone. Nowhere does it say these two things are exclusive that I could find, nor does it make any logical sense for them to be. If this is a bug, I just want to know so I can accept it and stop banging my head against it (a planned fix date would be nice too). If not, how can I get both the key on the keyboard and the EditText box to show my beamed eighth note. I am open to any suggestion or work arounds. Thanks.
Use a HashMap to map the android:codes to your unicode character.
In XML :
<Key android:codes="719" android:keyIcon="#drawable/zo"/> //use your icon and required code here
In java code:
HashMap<String, String> keyCodeMap = new HashMap<String, String>();
keyCodeMap.put("719", ""+'\u0986');
Then, in the onKey(int primaryCode, int[] keyCodes) method get the corresponding character using using following code:
String c = keyCodeMap.get(String.valueOf(primaryCode));
Use the value of c where you need.
Not sure if this is really going to help, since it's for AnySoftKeyboard, but the problem is the same, so maybe the solution is too?
What solved the problem (for me, creating a layout for ASK) was this:
supply both keyIcon and keyOutputText AS WELL as android:codes, but NO keyLabel!
keyLabel gets filled (by ASK?) with the first letter of android:codes, but you still see the image and it outputs multi-letter text.
Hope it helps, might be worth a try in any case, I guess.
(Please note: I just found this out and although I could reproduce it, I can't guarantee if it really was this that solved the problem. I honestly think so, though.)
Instead of using \u266B in android:codes try the int value of the unicode: 0x266B.
Then from onKey you can convert it back to String using:
Character.toString((char)primaryCode)