Is it possible to record the audio that comes out of the iPhone?
Asked Answered
E

2

9

I am working on an app that allows the user to create a sort of dub. There is an audio file playing, and the user can tap at certain moments to insert sound (kind of like a censor button.) I'm wondering how to go about capturing the final product.

Capturing audio directly from the iPhone seems the easiest route, as the user already hears the finished product as it is made. However, I can't find anything on how to do this. If not possible, are there any suggestions?

Eisinger answered 8/1, 2016 at 21:57 Comment(4)
Hi, I believe you can take a starting point in here zathras.de/programming/cocoa/UKSoundFileRecorder.zip/… Despite it is for MacOS I believe it will work for iPhone as wellGrouping
One question: The audio that is being played.., is from the same app that you are going to use to censor it?Lachman
@HugoAlonso Yes, that is correct.Eisinger
Then, yes, is possible.Lachman
I
1

The best way would probably be to be using the AV Foundation framework for mixing and then buffering the audio as well as playing it. This would allow for a high abstraction level while guaranteeing both played back and saved audio to be equal.

Apart from that: from a How can I achieve this with minimum code-perspective, without more information about your setup, the question is way too broad and/or opinion-based.

Interpretation answered 13/1, 2016 at 15:1 Comment(1)
I don't think it's too broad. I meant to find out if there is a simple way to capture the audio from the iPhone, similar to how there is a simple way to screenshot images.Eisinger
L
1

You will have to work with buffers. Don't know right now how it is done in Swift but you can implement it in Obj-C and then bridge it out.

You can refer to this answers here in StackOverflow (They are a bit old)

https://mcmap.net/q/944224/-record-audio-ios

https://mcmap.net/q/1320173/-can-avaudiorecorder-be-used-to-record-audio-coming-from-your-ios-app

and a project also exists (but is in Obj-C) https://github.com/alexbw/novocaine

Mainly the idea for your case would be to have 2 separated buffers and your sound effect. Then, you will be playing from buffer A (your music) and copying played data into buffer B (final Output) unless you are playing the effect. In wich case you will be copying the effect data into your buffer B.

Other option is to do it offline:

  1. Play your music (or audio) and keep a timer running synced with the elapsed time of your "to be censored audio".
  2. Save the timestamp of when you start and end tapping the censor button (for example).
  3. Overlap buffer A with your effect in those recorded (start-end) timestamps.

  4. Save the buffer as a file (or do whatever you need to do with it)

UPDATE:

You should take a look into the Apple implementation of something like this: https://developer.apple.com/library/ios/samplecode/AVAEMixerSample/Introduction/Intro.html

Lachman answered 14/1, 2016 at 17:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.