在 iOS 后台录制分块音频

发布于 2024-10-25 12:08:39 字数 501 浏览 5 评论 0原文

我正在尝试找出一种在 iOS 应用程序后台录制音频并将其传输到服务器的方法。

当应用程序位于前台时,我几乎可以正常工作。我使用 AVAudioRecorder 记录输入 X 秒。一旦我收到已完成的回调,我就会再录制 X 秒。每个记录会话都存储到不同的文件中,我将这些文件异步发送到服务器。

但是,当我的应用程序进入后台模式时,这似乎不起作用。

进入后台时,当前记录会话会继续记录,直到 X 秒结束,但是在我可以开始另一个记录会话之前,我的应用程序会被暂停。

有什么想法吗?

这是我的回调代码:

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)aRecorder successfully:(BOOL)flag {
    NSLog(@"hello");

    [self initRecorder];

    [recorder recordForDuration:5];

}

I am trying to figure out a way to record audio in the background of an iOS application and have it streamed to the server.

I have pretty much got this working for when the app is in the foreground. I use AVAudioRecorder to record input for X seconds. Once I get the callback that this has finished, I record for another X seconds. Each recording session gets stored to a different file and I send these files asynchronously to the server.

However, this doesn't seem to work while my app goes into background mode.

When going into the background, the current record session continues recording until the X seconds are up, however my app gets suspended, before I can start another recording session.

Any ideas?

Here's the code for my callback:

- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)aRecorder successfully:(BOOL)flag {
    NSLog(@"hello");

    [self initRecorder];

    [recorder recordForDuration:5];

}

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

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

发布评论

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

评论(2

柠栀 2024-11-01 12:08:39

您无法在后台重新开始录制。

因此,请改用音频队列或音频单元 RemoteIO API,这将为您提供更小的音频“块”(回调缓冲区块),而无需停止音频录制。

如果您的网络协议需要,可将小型音频回调块连接成较大的文件块。

You can't restart recording in the background.

So use the Audio Queue or Audio Unit RemoteIO APIs instead, which will give you smaller "chunks" (callback buffer blocks) of audio without stopping the audio recording.

Concatenate small audio callback chunks into larger file chunks if needed for your network protocol.

等风也等你 2024-11-01 12:08:39

多任务处理支持后台音频播放,但后台音频录制是否支持还不是很清楚。不过,我还没有尝试过。音频单元 API 可能允许您在应用程序处于后台时继续录制音频。然而,这是一种伎俩,我想它可能会在某个时候被取消。

Background audio playing is supported with multitasking but it's not very clear that background audio recording is. However, I have not tried it. The Audio Unit API might let you continue to record audio while the application is in the background. However, this is kind of a trick and I Imagine it might get pulled out at some point.

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