I am trying to prototype code in playgrounds before putting it into my app. Can we record Audio using swift playgrounds and how?
Many thanks,
Feras A.
Below is my current attempt, But the audioFile does not have any length, properties or data :-
import UIKit
import AVFoundation
var soundRecorder: AVAudioRecorder!
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let OutputFilePath = documentsDirectory.appendingPathComponent("out.wav")
//set the settings for recorder
var recordSettings = [
AVFormatIDKey: kAudioFormatAppleLossless,
AVEncoderAudioQualityKey : AVAudioQuality.max.rawValue,
AVEncoderBitRateKey : 320000,
AVNumberOfChannelsKey: 2,
AVSampleRateKey : 44100.0
] as [String : Any]
try soundRecorder = AVAudioRecorder(url: OutputFilePath, settings: recordSettings)
soundRecorder.record(forDuration: 10)
let audioFile = try AVAudioFile(forReading: OutputFilePath)
I don't think it is possible. Since there is no device to record the audio but I think you can connect an external device and use it as your simulator
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With