I'm making kind of voip app, so I have to be able to play and record sound at the same time.
But.. when I play and record at same time, iphone's volume was very low.
I used
//kAudio
UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(audioCategory), &audioCategory);
and
I try to
UInt32 audioRoute = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRoute), &audioRoute);
but.. still volume is very low..
please help..!
P.S
I'm using playing sound by audioQueue and recording sound by audioUnit.
Have you set your volume using kAudioSessionProperty_InputGainScalar property prior to recording ?
BTW, this input gain property is only available from iOS5.
Related
I used the tutorial found here to record and playback a sound. The recording and playback work fine, but I can barely here the sound when I play it back. I've tried the following code:
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,
sizeof (audioRouteOverride),&audioRouteOverride);
I add it to my "play" method, right before I play the sound. I've also tried to add it to my viewDidLoad. Both of them make it so I can't here the playback at all. It seems to be working for others, but where should I add it?
I checked out SpeakHere, Apples example AVAudio app. The volume is very quiet. When I use the Voice Memos app, the recording is played back very very loud. Has anyone been able to play a recorded message and play it back that loud?
Try setting this property of AVAudioPlayer ...
#property float volume; /* The volume for the sound. The nominal range is from 0.0 to 1.0. */
What do you think is the best (i.e. most memory efficient) way of playing a few 30 second audio files (m4v) from the bundle within an app to the external speaker? The audio files have to play automatically as soon a specific view appears.
There is no mixing, etc. going on. However I'm listening to the microphone at the same time via AVAudioRecorder to measure a few noise levels/peak sounds etc. and react to them.
Thanks!
m4v are video files. Did you mean m4p?
Assuming you did, I'd say start with AVAudioPlayer
Since you're using input at the same time as playback, you'll want to set your Audio Session's category appropriately:
[AVAudioSession sharedInstance].category = AVAudioSessionCategoryPlayAndRecord;
// note that on the iPhone that category will send audio output to the
// phone earpiece rather than the speaker, so you have to redirect the output
// like so:
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (
kAudioSessionProperty_OverrideAudioRoute,
sizeof (audioRouteOverride),
&audioRouteOverride
);
Whenever I start an AVCaptureSession running with the microphone as an input it cancels whatever background music is currently running (iPod music for instance). If I comment out the line adding the audio input, the background audio continues.
Does anyone know of a way to record video clips with the microphone while continuing to allow background audio to play? I've looked around a lot, and can't seem to find any references to this behavior.
Thanks for any help!
Try setting kAudioSessionProperty_OverrideCategoryMixWithOthers as seen in https://stackoverflow.com/a/7426406/16572
Is the background music a looping track? -- if so you could make it a system sound and tell it to re-play when it finishes playing. The reason being you can only have tracks up to 30 seconds as a system sound.
Don't know if it helps -- but thats one approach :)
Cheers,
Michael
I had the same problem and used this in my app and it worked:
UInt32 audioRouteOverride = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,sizeof (audioRouteOverride),&audioRouteOverride);
I was able to record video and audio and at the same time play a sound out of the speakers.
In my app i record and play audio at the same time. The app is almost finished. But there is one thing, that annoying me. When audio session is set to PlayAndRecord, sounds become quiet in comparison with the same sounds with the SoloAmbient category. Is there any way to make sound louder using PlayAndRecord?
when you use the session for play and record, the playback comes out of the speaker used for the phone, otherwise it comes out the speaker located at the bottom of the phone. this is to prevent feedback. you can override this like so (but watch out for feedback, not an issue if you aren't doing both at once)
//when the category is play and record the playback comes out of the speaker used for phone conversation to avoid feedback
//change this to the normal or default speaker
UInt32 doChangeDefaultRoute = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);
this code works on 3.1.2, earlier sdk's you have to do differently.
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
status = AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
you have to be careful with this method, it will override even if you have headphones plugged in, you have to monitor interruptions and change the routes accordingly. much better now using 3.1.2
Ask the user to plug in headphones?
The headphone + mic combination doesn't suffer from this problem.
I don't know if it's a bug, a consequence of the audio hardware,
or if the quiet playback is just an intentional and hamfisted
way of getting cleaner recordings.
UPDATE
I found out that setting the PlayAndRecord session changes your audio route to the receiver.
Apparently the use case is for telephony applications where the user holds the device up to his ear.
If that doesn't violate the Principle of Least Surprise, I don't know what does.
I have got an audio file which is quite quiet.
I'm playing it using AVAudioPlayer, but I can barely hear anything, especially without headphones.
Is there a way to increase the volume of an audio record?
You have a volume property for that. If even at it's highest setting the volume is still too low, I think you should edit the media file in some kind of music editor (i.e. Audacity) and increase the volume there.
player.volume = 2.0;
The doco says that volume is "nominally" between 0 and 1.0,
which seems to suggest that you can overdrive it.
Good luck, and try not to accidentally deafen users.
Maybe, you can use SpeakHere Apple Sample, as I did. To increase audio volume on this sample you need to set Player to Speaker Mode.
Add this code in AQPlayer.mm:
OSStatus error;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
error = AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
if (error) printf("couldn't set audio speaker!");
Before this code:
XThrowIfError (AudioQueueSetParameter(mQueue, kAudioQueueParam_Volume, 1.0), "set queue volume");
Maybe it's to late but, I hope it helps.