Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use AVAudiorecorder in swift playgrounds?

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)
like image 739
FerasAS Avatar asked Jan 18 '17 12:01

FerasAS


1 Answers

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

like image 174
moe safar Avatar answered Oct 02 '22 13:10

moe safar