Dictation results for UITextField different than UITextView
Asked Answered
S

3

5

I can't seem to find any documentation on the speech to text option for text entry in iOS. I know you can do it manually with some the AV stuff, but the out of the box dictation you get when Siri is enabled has some quirks to it.

Try this. Open any iOS app you have with a search bar. This will be our UITextField experiment. Better yet, open Mail.app. You can't uninstall it, so I know you have it.

Say "123 Elm St. comma Fargo comma ND" What I get: 123 Elm St. comma Fargo comma Indy"

Pretty close to exactly what I said. No big deal right. That was a text field/search bar. Lets try this in a UITextView.

Open a new email, and go to the body of the email. Lets say the same thing.

Say "123 Elm St. comma Fargo comma ND" What I get: 123 Elm St., Fargo, ND"

That looks loads better! So what I want to know is, why does the UITextView get better recognition for punctuation and other commands than text fields do. This isn't just limited to commas, it goes across the whole spectrum.

Is there a way to specify what type of text I want dictated? Is there a way to change it so I get this punctuation recognition in a text field? Or can someone point me to some documentation that says this is why they are different and I'm totally screwed. Either way, some answers would be helpful. Thanks in advance.

UPDATE I've subclassed UITextField and checked for alternate phrases that might be coming back with the dictation, but there aren't. Just the original conversion is all I get.

Screw answered 9/6, 2014 at 19:26 Comment(0)
S
4

After playing around with the text field some more, and using some information from @Ricky, I figured out what is holding the dictation back. I was setting the returnKeyType to UIReturnKeySearch. Changing this to any of the other options gives me the dictation results I wanted. Changing back to Search and the results are full text results. This isn't documented anywhere.

This behavior isn't documented anywhere. Thanks to @Ricky for steering my thinking, even if it wasn't 100% the right answer. It did help me get to the bottom of the issue.

Screw answered 16/6, 2014 at 17:38 Comment(0)
A
2

I built a test harness to check this and discovered that I get different dictation results depending on the values I set in the UITextInputTraits protocol. Specifically:

myTextField.autocorrectionType = UITextAutocorrectionTypeYes; // or UITextAutocorrectionTypeNo
myTextField.spellCheckingType = UITextSpellCheckingTypeYes; // or UITextSpellCheckingTypeNo

influences the results of the dictation for UITextField. Note that the default values for both UITextField and UITextView are:

UITextAutocorrectionTypeDefault
UITextSpellCheckingTypeDefault

the UITextInputTraits documentation doesn't say so, but I guess it is possible the default behaviour varies between UITextField and UITextView OR (more likely) that auto-correct is turned off on certain fields such as search boxes, or even (as mentioned by @Ricky in his answer) that the app developer has elected to alter the results before presenting to the user.

Testing under iOS7.1, I can get "comma" conversion to "," to occur for both UITextField and UITextView. Also, even with auto-correct turned on, my pronunciation meant sometimes I got "Indy" rather than "ND" for both UITextField and UITextView.

UPDATE:

For the sake of completeness, below is a working test harness that supports conversion of "comma" to "," for both UITextField and UITextView. As implied by OP in his own answer - setting the auto correction and spell checking is not necessary to get this to work.

@implementation TestHarnessViewController {
    UITextField *myTextField;
    UITextView *myTextView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor grayColor]];

    myTextField = [UITextField new];
    [myTextField setFrame:CGRectMake(10, 100, 283, 23)];
    myTextField.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:myTextField];

    myTextView = [UITextView new];
    [myTextView setFrame:CGRectMake(10, 200, 283, 100)];
    [self.view addSubview:myTextView];
}

- (void)keyboardWillShow:(NSNotification *)note {
    //
}

- (void)keyboardWillHide:(NSNotification *)note {
    //
}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    return TRUE;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return [textField resignFirstResponder];
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range  replacementText:(NSString *)text
{
    return TRUE;
}

@end
Associate answered 16/6, 2014 at 6:13 Comment(3)
So are you saying that a text field with the autocorrectionType and spellCheckingType set to YES would return actual punctuation marks? I'm trying it with my setup and it is still returning my original results.Screw
Yes - for me under iOS7.1 I can get dictation into a UITextField to convert "comma" into ",". I'll strip out all the unnecessary stuff and post my test harness here when I get a chance in a few hours. Never mind - I just noticed you have posted your own reply where you have got the dictation working properly.Associate
What also helped me figure out what was happening was your test and you getting the correct results in the text field/view. Why was mine different, so I looked at my settings and started tinkering with things that might have affected it. Thanks for the help.Screw
J
1

I have tested on all the different fields in Mail.app. Here are the things that I found:-

The UITextField inside the UISearchBar is exactly like what you mentioned, it replaces any punctuation or shortcut into a whole word. I have tested it by saying "Double Comma" and it shows as ,,

The UITextView on the mail body is exactly like what you mentioned as well.

I have tested further on other UITextFieldfor To:, Cc:, Bcc: and Subject:. I found out that they behave just like UITextView. The "comma" command displays as ,

I opened the Reminder app and I tested the command on the Title which I believe it is a UITextField. The "comma" command also displays as ,

I further tested on the Calendar App and trying to add an event. I tested on the Title and Location. For both of them, the "comma" command also displays as ,

So, I believe that it is not the difference between UITextView versus UITextField. But it is a decision made by the Apple Engineer by replacing the punctuation or shortcut to become a whole word for UISearchBar. I think it is because punctuation or shortcut word does not make much sense when we are searching. When we are searching for something, we normally only remember the keywords. So, I believe Apple Engineer is trying to make the search to have as much complete word as possible.

I could not find any official documentation for my claim above for now. I will add it when I found it.

Jem answered 12/6, 2014 at 2:23 Comment(1)
Because you can have several lines of text in the To, CC, Bcc, and Subject, those are all likely UITextViews, which lends credence to what I have already found. Same for Reminders and Calendar. I don't think this answer has found anything new yet.Screw

© 2022 - 2024 — McMap. All rights reserved.