如何在iOS应用程序中快速保存受影响的音频?

问题描述

您好,我开发了一个有关声音的应用程序,并且给音调文件提供了一些效果,例如音调,可以播放受影响的音频,但是我想获得受影响的文件或保存受影响的音频,如何获得受影响的文件?谢谢

func playSound(rate: Float? = nil,pitch: Float? = nil,echo: Bool = false,reverb: Bool = false) {
    
    audioEngine = AVAudioEngine()
    
    audioPlayerNode = AVAudioPlayerNode()
    audioEngine.attach(audioPlayerNode)
    
    let changeRatePitchNode = AVAudioUnitTimePitch()
    if let pitch = pitch {
        changeRatePitchNode.pitch = pitch
    }
    if let rate = rate {
        changeRatePitchNode.rate = rate
    }
    audioEngine.attach(changeRatePitchNode)
    
    let echoNode = AVAudioUnitdistortion()
    echoNode.loadFactoryPreset(.multiEcho1)
    audioEngine.attach(echoNode)
    
    let reverbNode = AVAudioUnitReverb()
    reverbNode.loadFactoryPreset(.cathedral)
    reverbNode.wetDryMix = 50
    audioEngine.attach(reverbNode)
    
    if echo == true && reverb == true {
        connectAudioNodes(audioPlayerNode,changeRatePitchNode,echoNode,reverbNode,audioEngine.outputNode)
    } else if echo == true {
        connectAudioNodes(audioPlayerNode,audioEngine.outputNode)
    } else if reverb == true {
        connectAudioNodes(audioPlayerNode,audioEngine.outputNode)
    } else {
        connectAudioNodes(audioPlayerNode,audioEngine.outputNode)
    }
    
    // schedule to play and start the engine!
    audioPlayerNode.stop()
    audioPlayerNode.scheduleFile(audioFile,at: nil) {
        
        var delayInSeconds: Double = 0
        
        if let lastRenderTime = self.audioPlayerNode.lastRenderTime,let playerTime = self.audioPlayerNode.playerTime(forNodeTime: lastRenderTime) {
            
            if let rate = rate {
                delayInSeconds = Double(self.audioFile.length - playerTime.sampleTime) / Double(self.audioFile.processingFormat.sampleRate) / Double(rate)
            } else {
                delayInSeconds = Double(self.audioFile.length - playerTime.sampleTime) / Double(self.audioFile.processingFormat.sampleRate)
            }
        }
        
        // schedule a stop timer for when audio finishes playing
        self.stopTimer = Timer(timeInterval: delayInSeconds,target: self,selector: #selector(PlaySoundsViewController.stopAudio),userInfo: nil,repeats: false)
        RunLoop.main.add(self.stopTimer!,forMode: RunLoopMode.defaultRunLoopMode)
    }
    
    do {
        try audioEngine.start()
    } catch {
        showAlert(Alerts.AudioEngineError,message: String(describing: error))
        return
    }
    // play the recording!
    audioPlayerNode.play()
    
    
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...