Can an iOS app passivly listen for a certain sound? - ios

I know the iPhone responds to "hey Siri". Is there similar features that I can use in my app to listen for certain sounds? If so what is the name of the iOS framework to use?

No, there is no API for that. Hey Siri is part of the OS and has hardware-level support. Your app can only use the microphones while it’s running; there is support for keeping the app alive while it’s recording audio, but the battery impact would be severe—the device can’t go to sleep—so it would be extremely unlikely to pass app review. That said, if you’d like API support to be added in future, please file an enhancement request with the use case you have in mind.

Yes sure, you can implement a recorder that records from the microphone and then you check anything you may need from recorded files.
Btw, what do you mean by certain sounds?
I think it sounds a bit tricky so please elaborate on your question. What's the business reason? How will you perform "listen for certain sounds"? How do you check it for being "certain". I think it's quite a hard thing to do using iOS but maybe I got your question wrong.
UPDATE: According to your comment: yeah it's possible but not like "hey ios check if it's a gunshot" :)))
But I think you can do it by checking the volume of the sound. If it is loud then it's a gunshot. I think it will work since user will use it on purpose. Check this link.
Also, I saw a similar app for gun shooters. So I'm sure it's doable:)
So shortly: find the way to: 1. use microphone. 2. Listen to sounds. 3. Check the sound for volume/length 4. Try detecting by testing
PS: Be careful with shooting while coding :)

If your "certain" sounds are referring to spoken words. Apple has the Speech Recognition framework for determining particular words.
If you are trying to measure perhaps a particular frequency however, Like many guitar tuner apps use or other music recording type app, I would recommend checking in depth AVFoundation 's guide to audio engineering.

Related

iOS : is it really impossible to get info of current track being played in third-party apps (like Spotify)?

So far, I have red many conflicting answers about this.
In this SO thread, it is said to use:
let player = MPMusicPlayerController.systemMusicPlayer()
if let mediaItem = player.nowPlayingItem {
// ...
}
However, this only works with the iOS player. If the current song is being played by Spotify for example, mediaItem will be nil.
I understand that Apple's policy doesn't allow to access any other application's data. The only thing I am able to do right now is to know if a song is playing from another player with the help of AVAudioPlayer's secondaryAudioShouldBeSilencedHint and isOtherAudioPlaying.
I want to know, however, if there is another way to access it, like using Spotify framework? (I am absolutely non familiar with it, that's just making assumptions).
Thanks for your help.
I am not sure about iOS but the current track can be read from Spotify on a Mac via AppleScript. I use this technique from Objective C. If you're interested I can post the code.
Spotify publish their API for AppleScript here https://developer.spotify.com/applescript-api/
If you're looking for a generic way of determining what is playing then I think that you will be disappointed. Each application will have a different way of retrieving this information.
So yes and no. If you want to specifically only check if Spotify is playing, then perhaps the Spotify iOS SDK provides functionality for such a thing. I really don't know about that SDK's functionality.
I would venture to guess that your actual goal is to see if any third party framework is playing; Pandora, Tidal, Apple Music, Amazon Prime Music, etc. In which case, you would need a framework for each one that provided such functionality.
Apps are sandboxed from each other for security, so yes, there is no way to tell the current track information other than if you have the framework in place and it provides that functionality.

How to get another app's currently playing audio [duplicate]

This question already has an answer here:
Audio Information of Current Track iOS Swift
(1 answer)
Closed 6 years ago.
How can I access another app's currently playing audio - the actual audio item but metadata is welcome too. I can see that this question has been asked a lot but with few solutions being offered over the years. I understand apple's philosophy for probably not wanting an app to be able to do this. I also understand that such a request is probably outside of the iOS API. With that being said, I would really like some kind of solution.
Logically, I feel that
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo
should return the info for whatever is currently playing; however, as others have mentioned, this value is always nil for audio being played outside of your app. Notably, popular audio apps seem to fail to use the MPNowPlayingInfoCenter class, making such audio fail to appear.
If using the default music app, one can use
MPMusicPlayerController.systemMusicPlayer().nowPlayingItem
However, what is a more consistent way to access audio playing through the podcasts app, Spotify, Pandora, Safari, etc?
Has anyone found a solution to this? Are there any old Objective-C frameworks that support this functionality?
One approach might be viable if there is there some way I can access the audio path of the item currently being played. For example, if I could get the path of the currently playing item, I could create an AV object from it:
AVAudioPlayer(contentsOfURL: audioUrl)
So is there a way I can get the audio url of the currently playing item and use it that way?
Is another approach better?
If a native solution does not exist, is it possible to bodge something together for it to work? Any advice or ideas welcome.
Edit: I don't believe anybody has been able to achieve this; however, I think a lot of people would like to. If this has been addressed, please link it! :)
This isn't currently possible in iOS. Just changing your AVAudioSession category options to .MixWithOthers, what will be an option to get info Song Info from other apps, causes your nowPlayingInfo to be ignored.
iOS only considers non-mixing apps for inclusion in MPNowPlayingInfoCenter, because there is uncertainty as to which app would show up in (e.g.) Control Center if there are multiple mixing apps playing at the same time.
Proposal: An option would be to use a music fingerprinting algorithm to recognize what is being played by recording it from your App.
Some interesting projects in this direction:
Gracenote https://developer.gracenote.com/ Gracenote (which is owned by Sony) has opened up it's SDKs and APIs and has a proper dev portal.
EchoNest & Spotify API http://developer.echonest.com/ Fusioned with Spotify since March 2016
ACRCloud https://www.acrcloud.com/ offers ACR solutions for custom files such as TV commercials, music tec

Block and/or Silence incoming notifications

My company is currently contracted to write a meditation app. While we have the app 90+% done the client has come up with a new requirement they would like implemented. Thankfully we have not agreed to the new requirement as we were not sure if it is possible or not.
They have seen in other apps (games were the only examples they were able to provide) where notifications (i.e. incoming email) did not appear and did not play a sound.
I have searched the old google god and have not been able to come up with an answer for my higher ups. Is there a way to accomplish this or is this something that is only available for games?
Thanks.
I don't think it is possible. The only thing that I would guess is that you would turn on do not disturb pragmatically. But there is no code for that, that i know of.

Possible to use Apple system sounds in my iOS app?

Can you use the system sounds in your iOS app? I'm looking to have the same list that is used in the default timer app (Marimba, Alarm, Doorbell etc).
Reason i'm asking is that in Apple's own Multimedia docs it says:
Note: System-supplied alert sounds and system-supplied user-interface sound effects are not available to your application. For example, using the kSystemSoundID_UserPreferredAlert constant as a parameter to the AudioServicesPlayAlertSound function will not play anything.
Then i've come across this list of system sound ID's.
So can you use access and use these sounds in your own apps which will pass Apple's review process? If not are similar sounds available open source?
Actually if you use AudioToolbox/AudioToolbox.h framework and import it in your header file for the view controller, you can play Apple system sounds without jailbreaking. For example, putting
AudioServicesPlaySystemSound(0x450);
under an IBAction will play the Apple 'click' sound on the execution of the action.
Also, to hear the system sounds referenced earlier, there is a great app available on github that works on your iPhone (not the iOS simulator) that has the sounds for you to click and hear, as the documentation references them, but you cannot hear them. The app is nice to listen to and then find the corresponding reference number.
No, you are not able to access this sounds, until jailbreak, after jail break you can access this sounds like below.
AudioServicesPlaySystemSound(1000);
i hope this files are copyrighted.

Voice Control iOS

I would like to build a simple reader app for the iPad 2 that would allow users to navigate/read via voice controls. The app would allow the user to enter a mode where the microphone was live and listened for predefined keywords like 'down', 'up', 'next', 'back', 'home', etc.
I don't want to reinvent the wheel on this so I'm just wondering first, if someone has done this already and if not, are there any good tutorials or SDKs available to help with recording someone's voice, and then comparing future output to see if it matches, or just dealing with the microphone in general?
Let's put aside that this is a fairly vaguely worded question for the moment.
If you are expecting to allow voice control in your app that somehow works throughout the entire device, it's just not possible. Your app would only work to control itself -- or at least itself and whatever external hooks you can normally get to the rest of the device, like, say, playing a song out of the user's iTunes library.
If you're planning on doing this in a jailbroken environment, then you should find some open-source library that does voice recognition -- if there are any -- and start from there. Be prepared for a very long haul, though.
Dragon Mobile SDK is what you're looking for.
http://dragonmobile.nuancemobiledeveloper.com/
There maybe others voice recognition SDKs out there, but this is the only one I can think of from the top of my head.
You can find a library called CMU Sphinx. There's an iphone version for it called
PocketSphinx. See if it fits your needs.
I would like to build a simple reader app for the iPad 2 that would allow users to navigate/read via voice controls.
The iOS 13 new feature Voice Control fully meets your request because you can control your device and your app with your voice exactly the same as with touches.
It's also possible to define actions for some specific words for instance.
The device settings are perfectly well detailed to handle this amazing new feature (Accessibility - Voice Control):
If you need dedicated names to be read out in your app, use the accessibilityUserInputLabels property to define them.
That's definitely the built-in tool your need to reach your goal: no need to use external library or SDK, everything is natively provided. ;o)

Resources