Search code examples
cocoamacosmp3wavqtkit

Easy way to decode mp3 into wav programmatically?


Is there an easy way to convert mp3s to wavs on a mac (programmatically) with (maybe with QTKit)? I've seen the SoundConvert example but to be honest I just don't understand it :P I need it to pass it to libofa for audio fingerprinting...


Solution

  • I found it! I leave it here, somebody might find it useful.

    NSError *error = nil;
    
    NSString *inputFile = [NSString stringWithFormat:@"./in.mp3"];
    NSString *outputFile = [NSString stringWithFormat:@"./out.wav"];
    
    QTMovie *movie = [QTMovie movieWithFile:inputFile error:&error];
    
    if (error) {
        #warning handle errors
    }
    
    NSDictionary *exportAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [NSNumber numberWithBool:YES], QTMovieExport,
                                      [NSNumber numberWithLong:kQTFileTypeWave], QTMovieExportType, nil];
    
    
    if (![movie writeToFile:outputFile withAttributes:exportAttributes]) {
        #warning handle errors
    }