我搜索了很多,找不到任何相关的…我正在处理iOS音频文件,这里是我想要做的…
记录音频和保存剪辑(检查,我使用AVAudioRecorder做了)
>改变音调(勾选,使用狄拉克做了这个)
>修剪:(
我有两个标记,即起始&结束偏移和使用这个信息我想修剪记录的文件,并希望将其保存回来.我不想使用“寻找”,因为稍后我想同步播放所有录制的文件(就像时间轴中的Flash影片剪辑),然后最后我要导出为一个音频文件.
解决方法
以下是我用来从预先存在的文件中修剪音频的代码.如果保存或保存为其他格式,则需要更改M4A相关的常量.
- (BOOL)trimAudio
{
float vocalStartMarker = <starting time>;
float vocalEndMarker = <ending time>;
NSURL *audioFileInput = <your pre-existing file>;
NSURL *audioFileOutput = <the file you want to create>;
if (!audioFileInput || !audioFileOutput)
{
return NO;
}
[[NSFileManager defaultManager] removeItemAtURL:audioFileOutput error:NULL];
AVAsset *asset = [AVAsset assetWithURL:audioFileInput];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset
presetName:AVAssetExportPresetAppleM4A];
if (exportSession == nil)
{
return NO;
}
CMTime startTime = CMTimeMake((int)(floor(vocalStartMarker * 100)),100);
CMTime stopTime = CMTimeMake((int)(ceil(vocalEndMarker * 100)),100);
CMTimeRange exportTimeRange = CMTimeRangeFromTimetoTime(startTime,stopTime);
exportSession.outputURL = audioFileOutput;
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.timeRange = exportTimeRange;
[exportSession exportAsynchronouslyWithCompletionHandler:^
{
if (AVAssetExportSessionStatusCompleted == exportSession.status)
{
// It worked!
}
else if (AVAssetExportSessionStatusFailed == exportSession.status)
{
// It Failed...
}
}];
return YES;
}
还有Technical Q&A 1730,这给了一个稍微更详细的方法.