为 beyond verbal 录制 wav 文件 API

Record wav file for beyond verbal API

你好Everone希望你们一切都好

我在 iphone.able 上录制 wav 以录制和存储文件时遇到问题,但是当我上传到 Beyond Verbal API 时,响应是

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

MARK:- 记录音频路径

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

MARK:- 开始录制时长

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)
    }
}

这是由于转换而发生的问题。所以使用 .m4a 文件,然后转换为 .wav 文件。它会起作用。