Record and play louder volume avaudio - iphone

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. */

Related

iphone play and record low volume problem

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.

kAudioSessionCategory_MediaPlayback is silenced with ringer off?

according to the documentation the correct way to allow sounds to be played even if the ringer switch is set to off is like so:
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
I then throughout the app play short wav files that play perfectly using
AudioServicesPlaySystemSound(sysSound)
....until the ringer is switched off and then.....silence?
No matter what I do I cannot get the sound to play if the ringer is off?
Any one ..... please?
Did you try using AudioSessionSetActive(YES); at the end?
AudioServicesPlaySystemSound never plays while the ringer is switched off in my experience. If you play sounds using AVAudioPlayer instead, you should get the behavior you are looking for:
let player: AVAudioPlayer = try AVAudioPlayer(contentsOf: url)
player.delegate = self
player.play()
You will also need to activate the audio session before playing if you have not already. And set an audio session category that supports sounds while silenced like you already did. Consider stopping the audio session when no audio is playing to conserve battery life.
A notable difference between AudioServices and AVAudioPlayer is that if the ringer is silenced, AudioServices playback will return almost immediately while AVAudioPlayer will take the full length of the sound before completing. As far as I know, the only way to detect and respond to the user's ringer setting is to use AudioServices instead of AVAudioPlayer. If you just want to play while silenced though this should not be relevant.

iPhone Playing a sound clip while recording a video using UIImagePickerController ... possible?

I'm using openAL to play sounds. I have a view controller that lets users upload a video. I want to give them a 1 minute warning sound so that they know to wrap things up. I tried using a call to SoundEngine_StartEffect(warningSound); but it just doesn't play anything. Is there a work around to this?
Did you try to set mix with others?
UInt32 doSetProperty = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(UInt32), &doSetProperty);
It is in most cases a "must have", when trying to record and play at the same time.

Playing Audio in an iPhone App

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
);

AVCaptureSession cancels background audio

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.