我想在将它放入我的应用程序之前在游乐场中对代码进行原型设计。我们可以使用swift playgrounds录制音频吗?
非常感谢,
Feras A.
以下是我当前的尝试,但audioFile没有任何长度,属性或数据: -
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)
答案 0 :(得分:2)
我认为这是不可能的。由于没有设备可以录制音频,但我认为您可以连接外部设备并将其用作模拟器