Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dictation results for UITextField different than UITextView

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.

like image 829
Bill Burgess Avatar asked Jun 09 '14 19:06

Bill Burgess


2 Answers

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.

like image 104
Bill Burgess Avatar answered Dec 16 '22 13:12

Bill Burgess


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
like image 24
Mike Avatar answered Dec 16 '22 12:12

Mike