IFlySpeechRecognizerDelegate.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // IFlySpeechRecognizerDelegate.h
  3. // MSC
  4. //
  5. // Created by ypzhao on 13-3-27.
  6. // Copyright (c) 2013年 iflytek. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. @class IFlySpeechError;
  10. /*!
  11. * 构建语法结束回调
  12. *
  13. * @param grammarId 语法id
  14. * @param error 错误描述
  15. */
  16. typedef void(^IFlyOnBuildFinishCompletionHandler)(NSString* grammarId,IFlySpeechError * error);
  17. /*!
  18. * 语音识别协议
  19. * 在使用语音识别时,需要实现这个协议中的方法.
  20. */
  21. @protocol IFlySpeechRecognizerDelegate <NSObject>
  22. @required
  23. /*!
  24. * 识别结果回调
  25. * 在进行语音识别过程中的任何时刻都有可能回调此函数,你可以根据errorCode进行相应的处理,
  26. * 当errorCode没有错误时,表示此次会话正常结束;否则,表示此次会话有错误发生。特别的当调用
  27. * `cancel`函数时,引擎不会自动结束,需要等到回调此函数,才表示此次会话结束。在没有回调此函数
  28. * 之前如果重新调用了`startListenging`函数则会报错误。
  29. *
  30. * @param errorCode 错误描述
  31. */
  32. - (void) onError:(IFlySpeechError *) errorCode;
  33. /*!
  34. * 识别结果回调
  35. * 在识别过程中可能会多次回调此函数,你最好不要在此回调函数中进行界面的更改等操作,只需要将回调的结果保存起来。
  36. * 使用results的示例如下:
  37. * <pre><code>
  38. * - (void) onResults:(NSArray *) results{
  39. * NSMutableString *result = [[NSMutableString alloc] init];
  40. * NSDictionary *dic = [results objectAtIndex:0];
  41. * for (NSString *key in dic){
  42. * [result appendFormat:@"%@",key];//合并结果
  43. * }
  44. * }
  45. * </code></pre>
  46. *
  47. * @param results -[out] 识别结果,NSArray的第一个元素为NSDictionary,NSDictionary的key为识别结果,sc为识别结果的置信度。
  48. * @param isLast -[out] 是否最后一个结果
  49. */
  50. - (void) onResults:(NSArray *) results isLast:(BOOL)isLast;
  51. @optional
  52. /*!
  53. * 音量变化回调
  54. * 在录音过程中,回调音频的音量。
  55. *
  56. * @param volume -[out] 音量,范围从0-30
  57. */
  58. - (void) onVolumeChanged: (int)volume;
  59. /*!
  60. * 开始录音回调
  61. * 当调用了`startListening`函数之后,如果没有发生错误则会回调此函数。
  62. * 如果发生错误则回调onError:函数
  63. */
  64. - (void) onBeginOfSpeech;
  65. /*!
  66. * 停止录音回调
  67. * 当调用了`stopListening`函数或者引擎内部自动检测到断点,如果没有发生错误则回调此函数。
  68. * 如果发生错误则回调onError:函数
  69. */
  70. - (void) onEndOfSpeech;
  71. /*!
  72. * 取消识别回调
  73. * 当调用了`cancel`函数之后,会回调此函数,在调用了cancel函数和回调onError之前会有一个
  74. * 短暂时间,您可以在此函数中实现对这段时间的界面显示。
  75. */
  76. - (void) onCancel;
  77. #ifdef _EDUCATION_
  78. /**
  79. * 返回音频Key
  80. *
  81. * @param key 音频Key
  82. */
  83. - (void) getAudioKey:(NSString *)key;
  84. #endif
  85. /**
  86. * 扩展事件回调
  87. * 根据事件类型返回额外的数据
  88. *
  89. * @param eventType 事件类型,具体参见IFlySpeechEventType的IFlySpeechEventTypeVoiceChangeResult枚举。
  90. * @param arg0 arg0
  91. * @param arg1 arg1
  92. * @param eventData 事件数据
  93. */
  94. - (void) onEvent:(int)eventType arg0:(int)arg0 arg1:(int)arg1 data:(NSData *)eventData;
  95. @end