【发布时间】:2020-02-10 18:47:56
【问题描述】:
目标:对话流语音机器人 API
我需要向 Dialog Flow Api 发送一个 wav 文件,并且格式和设置是预定义的。
- 所以我使用
AVAudioRecorder以.wav格式录制了音频 以下设置
audioFilename = getDocumentsDirectory().appendingPathComponent("input.wav")
let settings: [String: Any] = [
AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 16000,
AVNumberOfChannelsKey: 2,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: false,
AVEncoderAudioQualityKey: AVAudioQuality.max.rawValue
]
do {
audioRecorder = try AVAudioRecorder(url: audioFilename!, settings: settings)
audioRecorder.isMeteringEnabled = true
audioRecorder.prepareToRecord()
audioRecorder.delegate = self
audioRecorder.record()
recordButton.setTitle("Tap to Stop", for: .normal)
} catch {
print(error.localizedDescription)
finishRecording(success: false)
}
}
- 然后我尝试将其转换为
Base64音频格式
let outputFile = try Data.init(contentsOf: fileUrl)
let base64String = outputFile.base64EncodedString(options: NSData.Base64EncodingOptions.init(rawValue: 0))
print(base64String)
因此,每当我尝试使用 online converter 解码该编码字符串时,它都会显示一些损坏的字节
想法??
【问题讨论】:
标签: ios wav swift4.2 voice-recording