我想将数据库中的多段音频合成一段,需要使用什么插件或者可以直接使用函数完成拼接?
1条回答 默认 最新
- feitian_567 2019-04-03 14:52关注
不是很明白你的问题,可以描述得更详细些吗?
/**
音频合成@param paths 要合成音频的路径(NSURL)按照先后顺序
@param outputFilePath 合成后输出的路径
@param fileName 文件名称
@param success 合成成功
@param failure 合成失败
/
-(void)voiceCompoundWithVoicePaths:(NSArray *)paths outPutFilePath:(NSString *)outputFilePath withFileName:(NSString *)fileName compoundSuccess:(void(^)(NSString *path))success failure:(void(^)(NSError error))failure{// 音频合成 AVMutableComposition *composition = [AVMutableComposition composition]; AVMutableCompositionTrack *comTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; CMTime beginTime = kCMTimeZero; for (int i = 0; i < paths.count; i++) { NSURL *voiceUrl = paths[i]; AVURLAsset *voiceSet = [[AVURLAsset alloc] initWithURL:voiceUrl options:nil]; AVAssetTrack *voiceTrack = [[voiceSet tracksWithMediaType:AVMediaTypeAudio] firstObject]; [comTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, voiceSet.duration) ofTrack:voiceTrack atTime:beginTime error:nil]; beginTime = CMTimeAdd(beginTime, voiceSet.duration); } NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL judge = [fileManager fileExistsAtPath:outputFilePath]; // 判断该路径下是否存在对应的文件 if (!judge){ [fileManager createDirectoryAtPath:outputFilePath withIntermediateDirectories:YES attributes:nil error:nil]; } // 最终合成输出路径 NSString *outPutFilePath = [outputFilePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.m4a",fileName]]; // 添加合成路径 NSURL *fileUrl = [NSURL fileURLWithPath:outPutFilePath]; // 输出 AVAssetExportSession *assetExport = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetAppleM4A]; assetExport.outputFileType = AVFileTypeAppleM4A; assetExport.outputURL = fileUrl; // 优化 assetExport.shouldOptimizeForNetworkUse = YES; [assetExport exportAsynchronouslyWithCompletionHandler:^{ dispatch_async(dispatch_get_main_queue(), ^{ if (!assetExport.error) { //合成成功 success(outPutFilePath); }else{ //合成失败 failure(assetExport.error); } }); }]; }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog