2012-09-27 11 views
5

Yani iki ses dosyası, aynı formatta, potansiyel olarak farklı uzunluk var. Bu dosyaları birleştirmek istiyorum (sesi üst üste bindirip, uçlarında birleştirmeyin).Ses dosyalarını üst üste getirebilir ve iPhone için Xcode'da nasıl bir araya gelebilirim?

İki dosya var Sağlar ki:

  1. Ses Dosyası A, uzunluğu 30 saniye, boyut Ses Dosyası B, uzunluk 45 saniye, boyut 300k

Ne ediyorum 220k

  • örneğin, bir ses dosyasını birleştirir:

    1. Ses Dosyası C, uzunluk 45 saniye, boyut 300k (bunu fark edebilirim)

    Herkesin yardımına minnettarım!

  • +0

    Merhaba @Beat, Ses Dosyası C'nin dosya boyutunun çok büyük olması sorunum var. Bu problemin var mı? Eğer evet ise, bunu nasıl çözersiniz? thx – Newbie

    cevap

    4

    Uygulamamda yaptıklarım.

    - (void) setUpAndAddAudioAtPath:(NSURL*)assetURL toComposition:(AVMutableComposition *)composition 
    { 
        AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil]; 
    
        AVMutableCompositionTrack *track = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; 
        AVAssetTrack *sourceAudioTrack = [[songAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]; 
    
        NSError *error = nil; 
        BOOL ok = NO; 
    
        CMTime startTime = CMTimeMakeWithSeconds(0, 1); 
        CMTime trackDuration = songAsset.duration; 
        //CMTime longestTime = CMTimeMake(848896, 44100); //(19.24 seconds) 
        CMTimeRange tRange = CMTimeRangeMake(startTime, trackDuration); 
    
        //Set Volume 
        AVMutableAudioMixInputParameters *trackMix = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track]; 
        [trackMix setVolume:0.8f atTime:startTime]; 
        [self.audioMixParams addObject:trackMix]; 
    
        //Insert audio into track 
        ok = [track insertTimeRange:tRange ofTrack:sourceAudioTrack atTime:CMTimeMake(0, 44100) error:&error]; 
    } 
    
    
    - (IBAction)saveRecording 
    { 
        AVMutableComposition *composition = [AVMutableComposition composition]; 
         audioMixParams = [[NSMutableArray alloc] initWithObjects:nil]; 
    
        //IMPLEMENT FOLLOWING CODE WHEN WANT TO MERGE ANOTHER AUDIO FILE 
        //Add Audio Tracks to Composition 
        NSString *URLPath1 = [[NSBundle mainBundle] pathForResource:@"mysound" ofType:@"mp3"]; 
        NSString *URLPath2 = [[NSBundle mainBundle] pathForResource:@"mysound2" ofType:@"mp3"]; 
        NSURL *assetURL1 = [NSURL fileURLWithPath:URLPath1]; 
        [self setUpAndAddAudioAtPath:assetURL1 toComposition:composition]; 
    
        NSURL *assetURL2 = [NSURL fileURLWithPath:URLPath2]; 
        [self setUpAndAddAudioAtPath:assetURL2 toComposition:composition]; 
    
        AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; 
        audioMix.inputParameters = [NSArray arrayWithArray:audioMixParams]; 
    
        //If you need to query what formats you can export to, here's a way to find out 
        NSLog (@"compatible presets for songAsset: %@", 
          [AVAssetExportSession exportPresetsCompatibleWithAsset:composition]); 
    
        AVAssetExportSession *exporter = [[AVAssetExportSession alloc] 
                 initWithAsset: composition 
                 presetName: AVAssetExportPresetAppleM4A]; 
        exporter.audioMix = audioMix; 
        exporter.outputFileType = @"com.apple.m4a-audio"; 
        NSURL *exportURL = [NSURL fileURLWithPath:exportFile]; 
        exporter.outputURL = exportURL; 
    
    // do the export 
         [exporter exportAsynchronouslyWithCompletionHandler:^{ 
          int exportStatus = exporter.status; 
          NSError *exportError = exporter.error; 
    
          switch (exportStatus) { 
           case AVAssetExportSessionStatusFailed: 
    
            break; 
    
           case AVAssetExportSessionStatusCompleted: NSLog (@"AVAssetExportSessionStatusCompleted"); 
            break; 
           case AVAssetExportSessionStatusUnknown: NSLog (@"AVAssetExportSessionStatusUnknown"); break; 
           case AVAssetExportSessionStatusExporting: NSLog (@"AVAssetExportSessionStatusExporting"); break; 
           case AVAssetExportSessionStatusCancelled: NSLog (@"AVAssetExportSessionStatusCancelled"); break; 
           case AVAssetExportSessionStatusWaiting: NSLog (@"AVAssetExportSessionStatusWaiting"); break; 
           default: NSLog (@"didn't get export status"); break; 
          } 
         }]; 
    } 
    

    Bir süre önce bunu yaptığını dikkat ve çalışması için onunla bir nebze çalışmak zorunda olabilir. Ama bir noktada işe yaramadı. Sorun yaşarsan bana haber ver.

    +0

    hi @ gg13, Sesleri karıştırmak için önerilen yolunuzu kullandım. Ama benim problemim ihraç edilen dosyanın orijinal olanlardan çok daha büyük olmasıdır. Dosyayı daha küçük bir dosya türünde işlemenin herhangi bir yolu var mı? – Newbie

    +0

    Exporter.outputFileType'ı AVFileTypeAIFC gibi diğer dosya biçimlerine değiştirmeyi denedim. Ancak, hata atar. Sonra ihracatçının supportedFileTypes özelliğini okudum ve bunun sadece AVFileTypeAppleM4A'yı (yani, önerdiğiniz dosya türünü "com.apple.m4a-audio") desteklediğini öğrendim. Neden? – Newbie

    +0

    Trackmix'in sesini 0,8 olarak ayarladığınızı görüyorum. Kaliteyi bozmamak için gerekli olan tek adım bu mu? Çok az ses karıştırıcı biliyorum ve dosyaları birleştirirken kötü sonuçlar alıyorum, bu yüzden bunu deneyeceğim, ama bit hızını artırmaya yardımcı olup olmadığını biliyor musunuz? Örneğin, iki ses dosyasını 44.1'de birleştirirsem, eğer birleşik dosya 88.2 ise (veya daha yaygın olan 96), ya da bunu yapmak için bir neden olmazsa sonuç daha iyi olur mu? – Sti

    0

    Eğer Audio Asset parça seçili varlıkta değilse. Belirli bir Videonun sesini kontrol etmek için bu ifadeyi kullanabilirsiniz.

    if([[songAsset tracksWithMediaType:AVMediaTypeAudio] firstObject]==NULL) 
    { 
        NSLog(@"Sound is not Present"); 
    } 
    else 
    { 
        NSLog(@"Sound is Present"); 
        //You will initalise all things 
        AVAssetTrack *sourceAudioTrack = [[songAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]; 
    
    } 
    
    İlgili konular