How to change the audio routing at system level in iOS sdk? - ios

Is it possible to change the audio route when headphones are plug in or unplugged at iPhone's system level. Actually i want to listen the input and output audio only from internal iphone microphones whether headphones is connected or not.I have tried with kAudioSessionOverrideAudioRoute_Speaker , it is working fine at application level but not at system level. It is an enterprise applications. Any idea? please help me.

As per Audio session programming guide from Apple. You can only force play a audio file through iPhone speakers from app level by using setting kAudioSessionProperty_OverrideAudioRoute to kAudioSessionOverrideAudioRoute_Speaker. AFAIK system level it is not possible

Related

Selecting USB connected iphone as audio output for Mac

I am trying to build a project that will allow me to use an iphone USB connected to a Mac as an audio output device. There are options to do this wirelessly like "AirFoil" but they all introduce latency during playback.
When connected via USB, the iphone will appear in Audio Midi Setup as a device. Currently it is only selectable as an input device. I believe it can be used as an external microphone or a midi input device. My hope is that through code, the grayed output selection could be overridden. Is this even possible?
Iphone_IO.png
From what I've read the AVAudioEngine might provide a solution to this? I have read through posts about listing all available AudioDevices by ID.
list-all-available-audio-devices
From here would I be able to set the audio output device as the iphone? Or is this something that would require a companion app running on the phone to route the audio as well? Any information would be helpful, thanks!

Cordova detect switch audio mode - built-in speaker to bluetooth speaker

I have built a musical webapp with Cordova (7.1.0) and I use the web audio API to manage sounds. My question is:
How can I check which audio source the player has been choose? Built-in audio VS bluetooth audio.
For example on the iPhone, during playing a game I can select to play sounds directly via my devices speakers (built-in speakers) or I can switch to my bluetooth speakers. How could I check via JavaScript when the user is switching from one mode to the other one?
I found a Cordova plugin about listening the headset state (plugged or not). This works well for wired headphones, but it doesn't work to detect when built-in speaker are switched to bluetooth speaker.
I found a Cordova plugin about listening the bluetooth state (connected or not). But this doesn't tell me when the user is switching mode...
Any ideas would be welcome!
This Cordova plugin might be what you are looking for? https://github.com/saghul/cordova-plugin-audioroute
It's supposed to hook onto AVAudioSessionRouteChangeNotification and detect when the system audio route changes. According to the README You should be able to add the plugin and then place an event listener inside your project like so:
document.addEventListener('audioroute-changed',
function(event) {
console.log('Audio route changed: ' + event.reason);
// code for stuff you want to do
}
);
AVAudioSessionRouteChangeNotification is also mentioned here in a similar question:
Detect (listen to) audio route change in iOS 7
AVAudioSessionRouteChangeNotification documentation:
https://developer.apple.com/documentation/avfoundation/avaudiosessionroutechangenotification

Monitor volume level when using headphones

I'm looking to create an iphone app to help people monitor whether they are experiencing hearing loss from turning up the sound too high on their earbuds for a research project.
To do this, I want to periodically poll the volume level when music is playing on the iphone and the headphones are plugged in.
I did find the following answers that indicate it is possible however I am not familiar with iphone development.
checking when the audio is playing on the phone
Can my app be notified when another application starts/stops playing audio?
check if headphones are plugged in
Are headphones plugged in? iOS7
checking the volume level on the phone
https://stackoverflow.com/a/29170927/1361960
In Apple-way you cannot make app be notified when another application starts/stops playing audio.
Since the background execution of your app was limited according to the document.
Your code will only be executed when your application was running.

Approximating audio latency in iOS for airplay, bluetooth and related technologies

Is there a method of determining the delay in audio when playing to bluetooth (or some other device, like airplay) on iOS?
I've searched and found a few things. The advanced audio distribution spec, for example, makes several references to "delay" reporting, but I'm not clear how to access this from iOS in the more general case of audio playback to some device.
If there were a method, iOS would use that method to play videos with the audio and video in sync which it doesn't seem to do. However, I do see some references to other systems being able to compensate for this (eg apparently the android YouTube player can compensate: Detect or Approximate Bluetooth Latency on Android (Audio Playback))
I came across this issue myself. AvAudioSession provides properties for outputLatency
as well as inputLatency. I do see differences in the values when I connect to a pair of bluetooth headphones, vs the iPhone microphone and speaker, though I cannot speak to how accurate these numbers are.

BlueTooth headset not able to use as audio recording capture for iOS and OpenEars

We are building an iOS app that does basic speech recognition. Basically, the app counts the number of words you speak into the iOS device. The app works well when speaking into the standard microphone built into the iPhone. However, when connecting a wireless Bluetooth audio device, we are unable to use that Bluetooth device as a method for recording voice audio. We are using following software and devices:
built for iOS7.0/7.1 with the OpeanEars library for speech recognition
we’re using the ZOMM Wireless Leash (http://www.zomm.com/ | http://www.amazon.com/ZOMM-Wireless-Bluetooth-Speakerphone-Black/dp/B003N3J6BU/ref=sr_1_1?ie=UTF8&qid=1409515088&sr=8-1)
Tried other Bluetooth devices with the same behavior (Bluedio 66i and Bluedio DF200)
Unable to capture audio in default Voice Memo app
as far as we know this is simply using standard BlueTooth protocol, as we understand it, once the bluetooth device is paired it should automatically start accepting it as a device for recording/audio capture
According to OpenEars, the Bluetooth audio devices should be picked up automatically (http://www.politepix.com/forums/topic/enabling-bluetooth-support/). Are we right in assuming this?
We used the VoiceMemo app (the voice recording app that ships with iOS) to test out the bluetooth device as a “control” experiment:
Pair the ZOMM with the iOS device
Open VoiceMemo
Select ZOMM as input device from within the VoiceMemo app
Start recording
Stop recording – no audio was captured
Unfortunately this meant that neither our app nor the standard voice recording app is able to use the bluetooth device as a means for recording audio. Either way it’s hard to rule the device as simply the issue.
We’re curious to understand if this simply a hardware issue (and need a BT-enabled device that supports voice recording to iOS) or if there is something in the code we need to enable in order for the app to start accepting the device as recordable.
Also, more details about the ZOMM headset:
ZOMM specifications:
Bluetooth Wireless Compatibility:
This ZOMM device supports the following Bluetooth wireless protocols and profiles:
• Bluetooth core technology v2.1+EDR
• Hands-Free Profile (HFP) v1.5 headset role
• Headset Profile (HSP) v1.2 headset role
Bluetooth Wireless Interoperability:
This ZOMM device is designed to be interoperate with all Bluetooth wireless products that support compatible profiles and roles
including:
Bluetooth core technology v3.0, v2.1+EDR, v2.0 +EDR, v1.2
Bluetooth master and slave roles
Bluetooth Hands-Free Profile (HFP) v1.5 and prior headset (HS) role
Bluetooth Headset Profile (HS) v1.2 and prior headset (HS) role
Any idea on what we could do to resolve this issue and use Bluetooth together with the OpenEars library on iOS7.1?
Thanks! Philip
testing with Voice Memo is logical, however the app may not be allowing the route the change when BT is connected. A detailed explanation is here. iOS: Using Bluetooth audio output (kAudioSessionProperty_OverrideCategoryEnableBluetoothInput) AudioSession
With OpenEars, I believe you can enable logging to track when the audio route changes. So, you can verify via logging that it is listening to where it should be or .... not listening. I would suggest upgrading as of this post http://www.politepix.com/forums/topic/small-bug-when-running-on-ios-8/ . If you scroll to the bottom you can see BT should work now.
Another test worth running is SaveThatWav within OE. I have not used it, but you should be able to verify what you are listening too.

Resources