简体   繁体   English

在后台iOS中录制分块音频

[英]Recording Chunked Audio in Background iOS

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. 我试图找出一种在iOS应用程序的后台录制音频并将其流式传输到服务器的方法。

I have pretty much got this working for when the app is in the foreground. 当应用程序处于前台时,我几乎得到了这个功能。 I use AVAudioRecorder to record input for X seconds. 我使用AVAudioRecorder记录X秒的输入。 Once I get the callback that this has finished, I record for another X seconds. 一旦我得到完成的回调,我再记录X秒。 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. 当进入后台时,当前记录会话继续记录,直到X秒开始,但是我的应用程序被暂停,然后才能开始另一个记录会话。

Any ideas? 有任何想法吗?

Here's the code for my callback: 这是我的回调代码:

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

    [self initRecorder];

    [recorder recordForDuration:5];

}

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. 因此,请使用音频队列或音频单元RemoteIO API,这将为您提供较小的“块”(回调缓冲区块)音频,而无需停止录音。

Concatenate small audio callback chunks into larger file chunks if needed for your network protocol. 如果您的网络协议需要,将小型音频回调块连接成更大的文件块。

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. 当应用程序在后台时,Audio Unit API可能允许您继续录制音频。 However, this is kind of a trick and I Imagine it might get pulled out at some point. 然而,这是一种技巧,我想想它可能会在某些时候被拉出来。

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

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