Mac os x app voice recording Generating file. but while playing that file sound is not coming

Question

I am creating mac os x app. using swift 3.2 i am able to record audio and its even creating audio file but while playing that file i am not getting voice. So what can be issue? because file is getting generated but its not giving sound while playing. Here is my code

func createRecorder() -> () {

    let currentDate = NSDate()
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "dd-MM-yy HHmmss"
    let fileName = "Recording on " + dateFormatter.string(from: currentDate as Date) + ".wav"
    let filePaths = NSSearchPathForDirectoriesInDomains(.musicDirectory, .userDomainMask, true)
    if let firstPath = filePaths.first {


        let recordingPath = "\(firstPath)/\(fileName)"
        let url = NSURL(fileURLWithPath: recordingPath)
        let selectedPreset = RecordingPreset.High
        do {
            recorder = try AVAudioRecorder(url: url as URL, settings: selectedPreset.settings())
        }catch {
            print("nope")
        }
        recorder!.isMeteringEnabled = true

    }

}



@IBAction func btnRecordPressed(_ sender: Any) {
    createRecorder()
     recorder!.prepareToRecord()
    recorder?.record()

}

@IBAction func btnStopPressed(_ sender: Any) {
    recorder?.stop()
}

}

Here is recording Setting

enum RecordingPreset: Int {
    case Low = 0
    case Medium
    case High

    func settings() -> Dictionary<String, Int> {
        switch self {
        case .Low:
            return [AVLinearPCMBitDepthKey: 16, AVNumberOfChannelsKey : 1, AVSampleRateKey : 12_000, AVLinearPCMIsBigEndianKey : 0, AVLinearPCMIsFloatKey : 0]

        case .Medium:
            return [AVLinearPCMBitDepthKey: 16, AVNumberOfChannelsKey : 1, AVSampleRateKey : 24_000, AVLinearPCMIsBigEndianKey : 0, AVLinearPCMIsFloatKey : 0]

        case .High:
            return [AVLinearPCMBitDepthKey: 16, AVNumberOfChannelsKey : 1, AVSampleRateKey : 48_000, AVLinearPCMIsBigEndianKey : 0, AVLinearPCMIsFloatKey : 0]
        }
    }

    func exportSettings() -> Dictionary <String, Int> {

        var recordingSetting = self.settings()
        recordingSetting[AVFormatIDKey] = Int(kAudioFormatLinearPCM)
        recordingSetting[AVLinearPCMIsNonInterleaved] = 0

        return recordingSetting
    }
}

Show source
| osx   | swift   | avaudiorecorder   | audio-recording   2017-08-17 13:08 0 Answers

Answers to Mac os x app voice recording Generating file. but while playing that file sound is not coming ( 0 )

Leave a reply to - Mac os x app voice recording Generating file. but while playing that file sound is not coming

◀ Go back