I want to direct iOS VoiceOver sound to headphone even if it's not plugged in.
In other words, while my app is open, VoiceOver sound (and other sounds played by me in app using AVSpeechUtterance etc.) should NEVER go to speakers, but should come out of headset, if connected.
Can anyone suggest something on this?
iOS devices will not power-up the headset jack for audio output unless a recognized (proper impedance, etc.) headset or headphone is currently plugged in to the jack.
VoiceOver audio will always go to the headset, if a valid one is plugged-in, and not over-ridden.
Apparently it's not possible to forcefully direct sound to headphone unless an accessory is plugged to headphone jack (which activates a physical switch to direct voice to headphone).
I've achieved my purpose using following code (in Swift) which directs VoiceOver and other sounds to phone speaker (from where we listen to phone calls) and silences loud speaker while my app is in foreground.
let session: AVAudioSession = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try session.overrideOutputAudioPort(AVAudioSessionPortOverride.None)
try session.setActive(true)
} catch {
print("Couldn't override output audio port")
}
Related
Does anyone know wether audio can be both recorded and played back in the background on the Apple Watch?
It's possible to playback audio in the background by adding the .longFormAudio policy on the audio session however this does not work with the .playAndRecord mode.
I'd like to be able to record audio from the device's microphone then play it back either through the device speaker or paired Bluetooth headphones.
The audio will also need to continue recording and playing if the user lowers their wrist and the watch display turns off.
I have a app that can play sound. it works fine in usually. However when I Repeatedly disconnect and connect the Bluetooth headset, iPhone status bar shows the Bluetooth headset has been connected, and sound play is not in Bluetooth output route(maybe built-in receiver or speaker).
In my code, the last few disconnect and connect have not been notified from AVAudioSession Route Change Notification. And I get current output route from [[[[AVAudioSession sharedInstance] currentRoute] outputs] firstObject] is also not the bluetooth output.
Is this an issue of iOS? and Can I handle it with code? cause I want to play sound in a Bluetooth route in above case.
Thanks!!!
I'm making a karaoke application. If the headphones aren't plugged in, my app works fine. (my voice and background music record together). It is successful, but when I do the same way with headphone then I listen to the recording. I can't hear the background music, but I hear the voice clearly. I attached the code below I used:
https://github.com/genedelisa/AVFoundationRecorder
The issue is that when the headphones are plugged in, the mic is not able to pick up and record the audio, only your voice. Obviously, when the headphones are not plugged in, this is not an issue.
I would recommend that you combine the music and the voice recording after the voice is recorded if the user was using headphones. Suggestions on how to do that can be found on this post: How to merge two mp3 files iOS?
Also, to check if headphones are plugged in check out this post: Are headphones plugged in? iOS7
I'm writing and iOS audio/video chat app with several pre-conditions:
I'm using PlayAndRecord category to establish a audio/video chat.
I have also a button to which allows user to switch to the phone speaker whenever he wants.
I'm using AirPlay to demo the app.
The issue is once I'm switching to speaker during my PlayAndRecord session I'm losing the AirPlay mirroring. Once speaker is disabled - Airplay is back.
How to handle Speakerphone without losing the AirPlay mirroring?
How to mute application sound when hardware mute button on iPhone and iPad is on.I want to detect that whenever hardware mute button is turned on and off my application sound will be turned on and off.
You need not listen to the event, just use appropriate audio session category.
AVAudioSessionCategoryAmbient or AVAudioSessionCategorySoloAmbient