我想录制声音并将其上传到FTP 我用这个来通过FTP https://github.com/Constantine-Fry/rebekka上传我的文件,我在swift 3中,所以让我们看看我的代码:
录制声音
@IBAction func rec(_ sender: Any) {
let file = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0].appending("/rec.m4a")
let url = NSURL.fileURL(withPath: file)
let format = AVAudioFormat(commonFormat: .pcmFormatFloat64, sampleRate: 32000, channels: 2, interleaved: true);
do {
recorder = try AVAudioRecorder(url: url, format: format)
recorder?.prepareToRecord()
recorder?.record()
} catch {
}
}
并将其上传到FTP
@IBAction func svp(_ sender: Any) {
recorder?.stop()
var configuration = SessionConfiguration()
configuration.host = "matr.fr"
configuration.username = "mat"
configuration.password = "a"
let file = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0].appending("/rec.m4a")
let filename = NSURL.fileURL(withPath: file)
let URL = filename
let path = "/rec.m4a"
Session(configuration: configuration).upload(URL, path: path) { (result, error) -> Void in
print("Upload file with result:\n\(result), error: \(error)\n\n")
}
}
但我有这个错误:
上传带有结果的文件: false,错误:可选(错误域= NSCocoaErrorDomain代码= 2“(null)”UserInfo = {NSFilePath = / Users / mathieu / Library / Developer / CoreSimulator / Devices / C30D070A-292C-4735-87AA-C3C13D0BCA28 / data / Containers /数据/ PluginKitPlugin / 9CDBEAD1-7170-4BB5-86AB-B1D58F148635 /文档/ rec.m4a})