我已经使用IQAudioRecorderController https://github.com/hackiftekhar/IQAudioRecorderController做了录音部分.它记录音频并保存到TemporaryDirectory.
我想知道如何上传实时而不保存音频剪辑.
这是录音部分
//Unique recording URLNsstring *filename = [[nsprocessInfo processInfo] globallyUniqueString];_recordingfilePath = [NstemporaryDirectory() stringByAppendingPathComponent:[Nsstring stringWithFormat:@"%@.m4a",filename]];// Initiate and prepare the recorder_audioRecorder = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:_recordingfilePath] settings:recordSetting error:nil];_audioRecorder.delegate = self;_audioRecorder.meteringEnabled = YES;// Recording start- (voID)recordingbuttonAction:(UIbarbuttonItem *)item{ if (_isRecording == NO) { _isRecording = YES; //UI Update { [self showNavigationbutton:NO]; _recordbutton.tintcolor = _recordingTintcolor; _playbutton.enabled = NO; _trashbutton.enabled = NO; } /* Create the recorder */ if ([[NSfileManager defaultManager] fileExistsAtPath:_recordingfilePath]) { [[NSfileManager defaultManager] removeItemAtPath:_recordingfilePath error:nil]; } _oldSessioncategory = [[AVAudioSession sharedInstance] category]; [[AVAudioSession sharedInstance] setcategory:AVAudioSessioncategoryRecord error:nil]; [_audioRecorder preparetoRecord]; [_audioRecorder record];}else{ _isRecording = NO; //UI Update { [self showNavigationbutton:YES]; _recordbutton.tintcolor = _normalTintcolor; _playbutton.enabled = YES; _trashbutton.enabled = YES; } [_audioRecorder stop]; [[AVAudioSession sharedInstance] setcategory:_oldSessioncategory error:nil];}} // Recording done-(voID)doneAction:(UIbarbuttonItem*)item{ if ([self.delegate respondsToSelector:@selector(audioRecorderController:dIDFinishWithAudioAtPath:)]) { IQAudioRecorderController *controller = (IQAudioRecorderController*)[self navigationController]; [self.delegate audioRecorderController:controller dIDFinishWithAudioAtPath:_recordingfilePath]; } [self dismissVIEwControllerAnimated:YES completion:nil];}解决方法 有各种方法来解决这个问题,一种方法是创建自己的AudioGraph. AudioGraph可以从麦克风或文件抓取样本.然后,您进入输出单元,但安装回调以获取采样帧.然后,您可以将其推送到您的网络类,然后可以逐个上传数据包.
一个很好的例子,显示如何将这些捕获的数据包写入磁盘是AVCaptureAudioDataOutput.
在这个例子中,数据包是写入ExtAudiofileWriteAsync.您必须将其替换为您自己的上传到服务器的逻辑.请注意,虽然您可以轻松地做到这一点,但一个问题是这将给您原始的音频样本.如果您需要它们作为波形文件或类似的,您可能需要等到录制完成,因为文件的标题需要有关包含的音频样本的信息.
总结以上是内存溢出为你收集整理的ios – 录制时实时上传音频剪辑?全部内容,希望文章能够帮你解决ios – 录制时实时上传音频剪辑?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)