seggy
seggy

Reputation: 1196

Record wav file for beyond verbal API

Hello Everone Hope you all are doing well

I have an issue regarding wav recording on iphone.able to record & store file but when i upload to Beyond Verbal API then response is

{"readyState":4,"responseText":"{\"status\":\"failure\",\"reason\":\"Bad Wave format header Unknown\"}","status":400,"statusText":"Bad Request"}

MARK:- record audio path

func getDocumentsDirectory() -> URL {
    let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
    let documentsDirectory = paths[0]
    return documentsDirectory
}

MARK:- Start Recording with duration

func startRecording() {
    let audioFilename = getDocumentsDirectory().appendingPathComponent("audioFile.wav")
    //        print(audioFilename)
    let settings = [

        AVFormatIDKey: Int(kAudioFormatLinearPCM),
        AVSampleRateKey: 41000,
        AVNumberOfChannelsKey: 2,
        AVEncoderBitRateKey:320000,
        AVLinearPCMBitDepthKey:16,
        AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue

    ]

    do {
        audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)
        audioRecorder?.delegate = self
        audioRecorder.isMeteringEnabled = true
        audioRecorder?.record(forDuration: 15)
        audioRecorder.record()

    } catch {
        finishRecording(success: false)
    }
}

Upvotes: 0

Views: 91

Answers (1)

Dharmesh Mansata
Dharmesh Mansata

Reputation: 4738

This is issue occur because of convert. So use .m4a file and then after go for convert into .wav file. it will work.

Upvotes: 2

Related Questions