8

Is it possible to record output audio in an app using Swift? So, for example, say I'm listening to a podcast, and I want to, within a separate app, record a small segment of the podcast's audio. Is there any way to do that?

I've looked around but have only been able to find information on recording microphone recording and such.

Alex Coleman
  • 601
  • 7
  • 18
  • No. You can't. For reasons that should be obvious to do with privacy and rights management. – marko Jan 07 '15 at 22:21
  • 2
    @marko When talking, it's good to have _some_ idea what one is talking about. – matt Jan 07 '15 at 22:31
  • The OP seems to want to intercept the output audio of *another application* in iOS in order to record it. Further, there is the implication that the source material isn't otherwise available, as you'd clearly obtain it that way, were that the case. This question is asked fairy frequently, and the answer doesn't change, nor is it likely to. Were it to be possible, it would allow apps to maliciously record of audio from phone (or VOIP) calls, and allow the digital audio of paid-for content to be used in a way that wasn't intended by the publisher. – marko Jan 07 '15 at 22:59
  • 2
    @marko And that is why my answer, to which your commented retort adds nothing constructive, explains what I believe _is_ possible. I draw the sharp distinction between tapping one's own audio and hijacking arbitrary sound output, the latter being impossible. But its impossibility has nothing to do with "privacy and rights management"; it has to do with the fact that there is no way to do it. – matt Jan 07 '15 at 23:32

2 Answers2

5

It depends on how you are producing the audio. If the production of the audio is within your control, you can put a tap on the output and record to a file as it plays. The easiest way is with the new AVAudioEngine feature (there are other ways, but AVAudioEngine is basically an easy front end for them).

Of course, if the real problem is to take a copy of a podcast, then obviously all you have to do is download the podcast as opposed to listening to it. Similarly, you could buffer and save streaming audio to a file. There are many apps that do this. But this is not because the device's output is being hijacked; it is, again, because we have control of the sound data itself.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Okay, so it seems like I would have two choices if I wanted to capture an audio segment of an "outside" podcast (one that I don't already have a full copy of): 1) buffer it from the source and record at a certain point; or 2) download it completely -- at which point I'd have access to the sound data, as you said -- and then, since I controlled the data, I could record a segment of it. Sound about right? – Alex Coleman Jan 07 '15 at 21:59
  • (1) sounds right, since this must be what apps that record radio streams are actually doing. As for (2), if you downloaded it completely you wouldn't _need_ to record a segment of it; the download _is_ a recording. – matt Jan 07 '15 at 22:22
  • Presumably the apps that record a stream are using Audio Queue Services or some similar bit of Core Audio. – matt Jan 07 '15 at 22:30
  • Ah, right... in (2), I assume I could somehow extract clips from the full download. – Alex Coleman Jan 07 '15 at 23:05
  • Certainly, just as it is easy to extract clips from any audio or video file. – matt Jan 07 '15 at 23:31
  • @matt, I am successfully using an audio engine to do a real time pitch change, but I am unable to save the results. After reading your comment, tapping seems to be the way to go, but I am only finding resources to tap the mic. Could you point me in the right direction? – user4812000 Dec 29 '15 at 21:59
  • I am essentially trying to find the same answer requested in this post: http://stackoverflow.com/questions/29012139/save-audio-file-with-changed-time-pitch-using-avaudioengine-in-swift – user4812000 Dec 30 '15 at 02:09
  • @user4812000 Do you found any solution? I'm not capable of tap the output audio. Maybe you can help me! – Carolina Mar 20 '19 at 14:01
1

I believe you'll have to write a kernel extension to do that

https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KEXTConcept/KEXTConceptIOKit/iokit_tutorial.html

You'd have to make your own audio driver to record it

It appears as though

That is how softonic made soundflowerbed.

http://features.en.softonic.com/how-to-record-internal-sound-on-a-mac

Paul Wand
  • 323
  • 5
  • 12
  • 1
    1st: Soundflower/SoundflowerBed has nothing to do with Softonic, they just redistribute it. It's was created by Matt Ingalls. – Teejay Oct 16 '19 at 21:43
  • 1
    2nd: SoundflowerBed is just an audio redirector, Soundflower is the kernel extensions. – Teejay Oct 16 '19 at 21:44