简体   繁体   English

如何在iOS中录制音频并将其作为NSData获取?

[英]How to record audio and get it as NSData in iOS?

I want to record some thing in my app and post it to some API.我想在我的应用程序中记录一些东西并将其发布到某个 API。 Please help请帮忙

You can follow this link for recording and saving audio in local iPhone storage (ex: Document Directory).您可以按照此链接在本地 iPhone 存储(例如:文档目录)中录制和保存音频。

Record audio file and save locally on iPhone 录制音频文件并保存在 iPhone 本地

Once you saved it you can convert file content as NSData保存后,您可以将文件内容转换为 NSData

NSDate *audioData = [NSData dataWithContentsOfFile:audioFilePath];
// audioFilePath is the path of audio either from document 
// directory or any other location.

This simple tutorial might help you这个简单的教程可能会帮助你

https://www.appcoda.com/ios-avfoundation-framework-tutorial/https://www.appcoda.com/ios-avfoundation-framework-tutorial/

Once you are done recording then you have to choose do you want完成录制后,您必须选择您想要的

 AFNetworking or NSURLConnection 

to send the audio to the server将音频发送到服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM