License | MIT |
ReleasedLast Release | Dec 2017 |
Depends on: | |
SHWOpus | ~> 0.3 |
SHWAnalyticsSDK | ~> 1.1 |
SocketRocket | ~> 0.5.1 |
自然语言服务SDK,目前用于英文的ASR和TTS.
Deploy target : iOS 8.0.
target 'YourProject' do
pod 'SHWNLSClient', '~> 1.0.8'
end
pod update
pod install
Get your AppKey in our web site.
appKey值可从新华智云接口人获取(网站建设中,目前请联系接口人)
[SHWNLSGlobleConfig setAppKey:@“Your_APPKEY”];
[SHWNLSGlobleConfig setAppSecret:@“Your_APPSECRET”];
语音只支持麦克风录制,长度限制15s
。
delegate方法,最终都在主线程中回调。
多次调用beginRecord,如果已经处于Recording状态,后面的调用无效。
language,英文传参数 "en-US",中文传参数 "zh-CN"。
@protocol SHWASRClientDelegate <NSObject>
@optional
/*!
Called when the asr procedure starts recording audio.
*/
- (void)asrClientDidBeginRecording:(SHWASRClient *)asrClient;
/*!
Called when the asr procedure stops recording audio.
*/
- (void)asrClientDidFinishRecording:(SHWASRClient *)asrClient;
/*!
Called when the asr procedure stops recording audio.
*/
- (void)asrClientDidFinishRecognizing:(SHWASRClient *)asrClient;
/*!
Called when the asr procedure returns a custom application response.
{data:{recognitionText:@""}, code:200}。
*/
- (void)asrClient:(SHWASRClient *)asrClient didReceiveServiceResponse:(NSDictionary *)result;
/*!
Called when the asr procedure has an error.
*/
- (void)asrClient:(SHWASRClient *)asrClient didFailWithError:(NSError *)error;
@end
@interface SHWASRClient : NSObject
+ (instancetype)initWithDelegate:(id<SHWASRClientDelegate>)delegate;
- (void)beginRecordWithLanguage:(NSString *)language;
- (void)finishRecordAndRecognize;
- (BOOL)isRecording;
- (void)cancel;
@end
长度没有限制,ttsClient:didReceiveAudio:sequence:会多次返回音频文件。
返回的NSData音频格式为mp3。
delegate方法,最终都在主线程中回调。
多次调用tts:language:,后一次会cancel前一次的请求。
language,英文传参数 "en-US",中文传参数 "zh-CN"。
@protocol SHWTTSClientDelegate <NSObject>
@optional
/*!
Called when the tts procedure returns audio data.
*/
- (void)ttsClient:(SHWTTSClient *)ttsClient didReceiveAudio:(NSData *)audioData sequence:(int)sequence;
/*!
Called when the tts procedure completes successfully.
*/
- (void)ttsClientDidFinish:(SHWTTSClient *)ttsClient;
/*!
Called when the tts procedure has an error.
*/
- (void)ttsClient:(SHWTTSClient *)ttsClient didFailWithError:(NSError *)error;
@end
@interface SHWTTSClient : NSObject
+ (instancetype)initWithDelegate:(id<SHWTTSClientDelegate>)delegate;
/**
* @prama language, pass nil will use default language en_us
*/
- (void)tts:(NSString *)text language:(NSString *)language;
- (void)cancel;
@end
项目使用了http协议,所以需要适配
在Info.plist
中添加NSAppTransportSecurity
类型Dictionary
。
在NSAppTransportSecurity
下添加NSAllowsArbitraryLoads
类型Boolean
,值设为YES
。
项目需要使用麦克风,需要适配
在Info.plist
中添加Privacy - Microphone Usage Description
类型NSString
。
错误码 | 错误类型 |
---|---|
0 | 无错误 |
1001 | 录音错误 |
1003 | 网络错误 |
1004 | 超时 |
1005 | 用户取消 |
1006 | 鉴权错误 |
1007 | ASR错误 |
1008 | TTS错误 |