在Swift中从视频中提取音频

时间:2017-02-24 15:36:59

标签: swift audio video avassetexportsession

我是来自Objective-C的Swift的新手并且遇到了障碍。我需要从.mov文件中提取音频,然后我可以通过语音到文本处理来运行它。到目前为止我的代码创建了一个文件,但它不包含音频。这是我到目前为止的代码

private var audioFilePath: URL!

private func createAudioFile(){
    let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
    let url = NSURL(fileURLWithPath: path)
    self.audioFilePath = url.appendingPathComponent("myAudio.m4a")

    let theAsset = AVAsset(url: self.outputFilePath)

    let exporter = AVAssetExportSession(asset: theAsset, presetName: AVAssetExportPresetHighestQuality)
    exporter?.outputURL = self.audioFilePath
    exporter?.outputFileType = AVFileTypeMPEG4

    print("file path = ", self.audioFilePath)

    exporter?.exportAsynchronously(completionHandler: {
        print("exporter?.status\(exporter?.status)")
    })
}

感谢您的帮助!

0 个答案:

没有答案