如何将音频编码为 u-law g.711?然后通过 http 将该音频发送到远程服务器。
AUDIO STREAM: Send a continuous stream of audio to the currently viewed camera. Audio needs to be encoded at G711 mu-law at 64 kbit/s for transfer to the Axis camera at the bedside. send (this should be a POST URL in SSL to connected server): POST /transmitaudio?id= Content-type: audio/basic Content-Length: 99999 (length is ignored)
我在 google 和此处进行了搜索,但我发现的主要是从服务器流式传输到 I 设备的方法,而不是相反的方法。我确实找到了这个帖子(http://stackoverflow.com/questions/7750329/how-to-send-audio-file-through-http-post-to-a-server-from-ios)但是它似乎喜欢答案描述性不强,也没有任何一个被接受。
这是我目前所拥有的。
{
NSNumber *formatObject;
switch (self.recordEncoding) {
case (ENC_AAC):
formatObject = [NSNumber numberWithInt: kAudioFormatMPEG4AAC];
break;
case (ENC_ALAC):
formatObject = [NSNumber numberWithInt: kAudioFormatAppleLossless];
break;
case (ENC_IMA4):
formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
break;
case (ENC_ILBC):
formatObject = [NSNumber numberWithInt: kAudioFormatiLBC];
break;
case (ENC_ULAW):
formatObject = [NSNumber numberWithInt: kAudioFormatULaw];
break;
default:
formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
}
[recordSettings setObject:formatObject forKey: AVFormatIDKey];
[recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
[recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
[recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];
}
这似乎是 U-law(因此得名编码),但是我对音频编解码器一无所知,也不知道 G711 mu-law 是否可以在 ios 上使用。
如何让我的音频以正确的格式编码?
然后如何将编码后的音频发送到服务器?现在我将它转到一个临时文件位置,但即使我更改了它,我也看不出这会有什么帮助。我知道这有很多要求,我不希望得到答案,但我需要一个起点,因为目前我完全不知道如何做到这一点。
最佳答案
录制完成后发送音频
self.request = [client multipartFormRequestWithMethod:@"POST" path:[NSString stringWithFormat:@"transmitaudio?id=%@",self.restClient.sessionId] parameters:parameters constructingBodyWithBlock: ^(id <AFMultipartFormData>formData)
{
NSError * error = [[NSError alloc]init];
[formData appendPartWithFileURL:self.audioHandler.soundFileURL name:@"sound.caf" error:&error];
// NSLog(@"error %@", [error localizedDescription]);
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:self.request];
[self.queue addOperation:operation];
关于objective-c - 通过 POST 命令将音频从 ios 流式传输到 REST 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10175738/