如何在我的应用程序上录制语音然后将其发送到服务器?

发布于 2024-12-11 23:08:16 字数 113 浏览 0 评论 0原文

我正在尝试构建一个可以在 iPhone 上录制声音(麦克风)的应用程序, 然后将它们发送到我的服务器上存储。

谁能帮我解决这个问题。 我什至不知道从哪里开始:)

非常感谢, 奥德.

Im trying to build an application that will record voices (mic) on my iPhone,
and then will send them to store on my server.

can anyone help me with this one.
i even don't know where to began with this :)

Thank you very much,
Oded.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酷到爆炸 2024-12-18 23:08:16
  1. 只需在 google 中搜索“如何录制 iphone”,几秒钟内即可获得。

  2. 录制后,文件将在您的文档文件夹中创建。

  3. 检索该路径并提取 NSData 中的数据并通过 POST 方法发送到服务器。

示例代码,

NSLog(@"SendingRecordedData");
    NSString *urlString = [NSString stringWithFormat:@"http://your_server/fileupload.php"];
    NSLog(@"Url:%@",urlString);

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"pics\"; filename=\"record.caf\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];



[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];


[body appendData:[NSData dataWithData:data2]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:body];
NSError *err;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&err];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
  1. Just google it "how to record iphone" and you get it in a seconds.

  2. After recording, file will create in your Documents folder.

  3. Retrieve that path and extract data in NSData and send to server through POST method.

Sample code,

NSLog(@"SendingRecordedData");
    NSString *urlString = [NSString stringWithFormat:@"http://your_server/fileupload.php"];
    NSLog(@"Url:%@",urlString);

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"pics\"; filename=\"record.caf\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];



[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];


[body appendData:[NSData dataWithData:data2]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:body];
NSError *err;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&err];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
疯到世界奔溃 2024-12-18 23:08:16

有录音示例代码 -

there is sample code with recording - SpeakHere on iOS developer site. After recording you can save it and send as any binary file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文