I have an application that records and then plays an audio file. Currently, sound is played through the speaker speaker. Can someone tell me how Swift will handle the encoding to make the sound go out of the speaker?
The following is one example that I use to play an audio file:
@IBAction func playAudioVader(sender: UIButton) { playAudioWithVariablePitch(-1000) } func playAudioWithVariablePitch(pitch: Float){ audioPlayer.stop() audioEngine.stop() audioEngine.reset() var audioPlayerNode = AVAudioPlayerNode() audioEngine.attachNode(audioPlayerNode) var changePitchEffect = AVAudioUnitTimePitch() changePitchEffect.pitch = pitch audioEngine.attachNode(changePitchEffect) audioEngine.connect(audioPlayerNode, to: changePitchEffect, format: nil) audioEngine.connect(changePitchEffect, to: audioEngine.outputNode, format: nil) audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: nil) audioEngine.startAndReturnError(nil) audioPlayerNode.play() } override func viewDidLoad() { super.viewDidLoad() audioPlayer = AVAudioPlayer(contentsOfURL:receivedAudio.filePathURL, error: nil) audioPlayer.enableRate = true audioEngine = AVAudioEngine() audioFile = AVAudioFile(forReading:receivedAudio.filePathURL, error: nil) }
xcode ios8 swift avaudioplayer
Unconquered82
source share