iOS 语音输入,返回结果异常,请高手指点
十****C · 十****C 发布于2017-08-01 13:16 浏览:2666 回复:2

- (void)TestAFNetWorking{

    

    NSString * POST_BOUNDS = @"b97dd7a3-c03e-4ad2-94d8-27ba4ed460d2";

    

    

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",

                                                         @"text/html",

                                                         @"image/jpeg",

                                                         @"image/png",

                                                         @"application/octet-stream",

                                                         @"text/json",

                                                          nil];

    

    

    [manager.requestSerializer setValue:@"fffffff-e760-8ffa-ffff-ffffd313f5d9" forHTTPHeaderField:@"dueros-device-id"];

    [manager.requestSerializer setValue:@"Bearer 23.788b073917ca41aa6d5e5450d64761b3.2592000.1501986691.2333075437-9855227" forHTTPHeaderField:@"authorization"];

    [manager.requestSerializer setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",POST_BOUNDS] forHTTPHeaderField:@"Content-Type"];

    

    

  [manager POST:@"http://dueros-h2.baidu.com/dcs/v1/events" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {

        

        

         NSString * jsonStr = @"{\"clientContext\":[{\"header\":{\"name\":\"PlaybackState\",\"namespace\":\"ai.dueros.device_interface.audio_player\"},\"payload\":{\"offsetInMilliseconds\":0,\"playerActivity\":\"FINISHED\",\"token\":\"\"}},{\"header\":{\"name\":\"AlertsState\",\"namespace\":\"ai.dueros.device_interface.alerts\"},\"payload\":{\"activeAlerts\":[],\"allAlerts\":[]}},{\"header\":{\"name\":\"VolumeState\",\"namespace\":\"ai.dueros.device_interface.speaker_controller\"},\"payload\":{\"muted\":false,\"volume\":80}},{\"header\":{\"name\":\"SpeechState\",\"namespace\":\"ai.dueros.device_interface.voice_output\"},\"payload\":{\"offsetInMilliseconds\":1,\"playerActivity\":\"FINISHED\",\"token\":\"\"}}],\"event\":{\"header\":{\"name\":\"ListenStarted\",\"namespace\":\"ai.dueros.device_interface.voice_input\",\"messageId\":\"8f6c0e7b-78e3-4be3-964b-e19e5f7e8c2d\",\"dialogRequestId\":\"17966ac1-a2e6-4cf7-aafe-bad4aff2287b\"},\"payload\":{\"format\":\"AUDIO_L16_RATE_16000_CHANNELS_1\"}}}";

        

        

      

      

      

      [formData appendPartWithFormData:[jsonStr dataUsingEncoding:NSUTF8StringEncoding] name:@"metadata"];

      

        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"raw"];

        

        

        NSData * fileData = [NSData dataWithContentsOfFile:filePath];

        

      

//      [formData appendPartWithFormData:fileData name:@"audio"];

      

        //上传的参数(上传图片,以文件流的格式)

        [formData appendPartWithFileData:fileData

                                    name:@"audio"

                                fileName:@""

                                mimeType:@"application/octet-stream"];

      



      

    } progress:^(NSProgress *_Nonnull uploadProgress) {

        //打印下上传进度

    } success:^(NSURLSessionDataTask *_Nonnull task,id _Nullable responseObject) {

        //上传成功

    } failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {

        //上传失败

    }];

}


点赞  ( 0 )
收藏
评论(2)
共2条回复 最后由q****2回复于2017-08-01 14:54
#2十****C回复于2017-08-01 13:34:41

棒棒哒

0
#3q****2回复于2017-08-01 14:54:20

棒棒哒

0
TOP