使用听写 - iOS 6 - DidStart? [英] Using Dictation - iOS 6 - DidStart?

查看:138
本文介绍了使用听写 - iOS 6 - DidStart?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已知的回复方式听写:


  • dictationRecordingDidEnd - 回应完成对a的认可口述
    短语。

  • dictationRecordingDidEnd - respond to the completion of the recognition of a dictated phrase.

dictationRecognitionFailed - 回应失败的听写识别。

dictationRecognitionFailed - respond to failed dictation recognition.

参考: UITextInput协议参考

Reference: UITextInput Protocol Reference

从iOS 5.1开始,当用户在支持的设备上选择听写输入时,系统会自动将识别的短语插入当前文本视图。 UITextInput协议中的方法允许您的应用程序响应完成听写,如使用听写中所述。您可以使用UIDictationPhrase类的对象来获取表示用户已指定的短语的字符串。在不明确的听写结果的情况下,听写短语对象提供包含替代字符串的数组。

Starting in iOS 5.1, when the user chooses dictation input on a supported device, the system automatically inserts recognized phrases into the current text view. Methods in the UITextInput protocol allow your app to respond to the completion of dictation, as described in "Using Dictation." You can use an object of the UIDictationPhrase class to obtain a string representing a phrase a user has dictated. In the case of ambiguous dictation results, a dictation phrase object provides an array containing alternative strings.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextInput_Protocol/Reference/Reference.html

推荐答案

据我所知,没有用于检测听写何时开始的公共API。

As far as I can tell, there's no public API for detecting when dictation has started.

如果你真的想要这样做,并且你想进入App Store,你可能会采用以下方法,但它是完全不受支持它可能会让你被拒绝,而可能会在iOS的未来版本中破解

If you really want to do it, and you want to be in the App Store, you can probably get away with the following approach, but it is totally unsupported, it might get you rejected anyway, and it is likely to break in a future version of iOS.

文本系统在更改到听写键盘之后发布一些未记录的通知。其中两个是在对其进行更改时发布的对其进行更改,并使用以下名称:

The text system posts some undocumented notifications after changing to or from the dictation "keyboard". Two of them are posted both on a change to it and a change from it, with these names:


  • UIKeyboardCandidateCorrectionDidChangeNotification

  • UIKeyboardLayoutDidChangedNotification

  • UIKeyboardCandidateCorrectionDidChangeNotification
  • UIKeyboardLayoutDidChangedNotification

注意第二个有一个奇怪的动词共轭。那不是拼写错误。 (好吧,这不是我的错字。)

Note that the second one has a strange verb conjugation. That is not a typo. (Well, it's not my typo.)

这些通知也会在其他时间张贴,所以你不能只是观察它们并假设听写状态已发生变化。收到通知后,您需要进行更多检查。因此,将自己添加为其中一个通知的观察者。第一个似乎不太可能在将来消失或重命名。

These notices are also posted at other times, so you can't just observe them and assume the dictation state has changed. You'll need to do more checking when you receive the notification. So, add yourself as an observer of one of those notifications. The first one seems less likely to go away or be renamed in the future.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(checkForDictationKeyboard:)
        name:@"UIKeyboardCandidateCorrectionDidChangeNotification"
        object:nil];
    ...

当您收到通知时,您会想知道是否听写视图显示:

When you receive the notification, you'll want to see whether the dictation view is showing:

- (void)checkForDictationKeyboard:(NSNotification *)note {
    if ([self isShowingDictationView]) {
        NSLog(@"showing dictation view");
    } else {
        NSLog(@"not showing dictation view");
    }
}

要查看它是否显示,请检查除了您的每个窗口拥有应用程序窗口通常,唯一的其他窗口是文本系统的窗口。

To see whether it's showing, check each window except your own application window. Normally, the only other window is the text system's window.

- (BOOL)isShowingDictationView {
    for (UIWindow *window in [UIApplication sharedApplication].windows) {
        if (window == self.window)
            continue;
        if (containsDictationView(window))
            return YES;
    }
    return NO;
}

递归地遍历视图层次结构,检查其类名称包含字符串的视图 DictationView。实际的类名是 UIDictationView ,但是不使用整个名称,你不太可能被App Store拒绝。

Recursively walk the view hierarchy checking for a view whose class name contains the string "DictationView". The actual class name is UIDictationView but by not using the whole name you're less likely to be rejected from the App Store.

static BOOL containsDictationView(UIView *view) {
    if (strstr(class_getName(view.class), "DictationView") != NULL)
        return YES;
    for (UIView *subview in view.subviews) {
        if (containsDictationView(subview))
            return YES;
    }
    return NO;
}

这篇关于使用听写 - iOS 6 - DidStart?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆