Can the AVSpeechUtterance audio be recorded? - avaudiorecorder

I am wondering if the audio from Siri's speech synthesis can be recorded programmatically and then saved locally.
I am wanting to create some custom voice alert audio files in Siri's 'voice' to be used to for spoken Push Notification messages instead of just using a generic sound alert.
eg I would get Siri to say "Attention David, your window has been closed due to rain" in a Push Notification alert by using a previously recorded voice file, even when the home automation App isn't running.

Related

How to customise push notification sound in iOS?

I am making a chat app. The user can select the notification sound for a particular chat/group. When the app is in the killed state, if a new message arrives I want to play the sound that the user had selected for that chat otherwise play default sound. How can I do this?
App bundle must have your all sounds file
User selected sound name and feedback to you app server
Your APN server get the selected sound and push notification with the sound name

Playing an audio clip even when the app is not running

In my app, I used VoIP notification to play a long alarm on app not running state as per suggestion Silent Push, But app got rejected in the following points
Your app is not in compliance with Guideline 4.2.1 using the VoIP API in a manner that it is not intended.
2.5.4 Multitasking apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc. If your app uses location background mode, include a reminder that doing so may dramatically decrease battery life.
Is there any way to rectify these issues or would be good if we get any alternative to play a long alarm on push receive in app not running state?
I beleive, UNNotificationContentExtension would help to show our custom notification on push receives but how to play automatic audio on push receive,
Can we handle in push message sound key?
or
Can we do this by default UNNotificationContentExtension methods in
mediaPlay() mediaPlayPauseButtonFrame()
But there is no way to play automatic audio here. please correct me if am wrong.
My requirement will be, I need to play a long audio in any app state and audio should stop on user click of stop button or notification(it usually launch our app).
You can't use background location/ VOIP for other purposes, so if you are using them just to keep your app active in the background, Apple will reject it.
Use them in your app only when it is directly relevant to the features and services provided by the app. Location-based APIs/VOIP shouldn’t be used to provide emergency services or alarm systems, etc. Ensure that you notify and obtain consent before collecting, transmitting, or using location data. If your app uses background services, be sure to explain the purpose in your app. Refer to the Human Interface Guidelines for best practices on doing so.
You can use sound key in your push but audio can only be played for maximum 30 seconds. There's no way like audio should stop when user taps on notification.

Is there a way to programmatically override remote push notification sounds using Swift?

I have a Swift iOS8+ app that receives remote push notifications from a 3rd party server over which I have no control.
That server sends push notifications as JSONs with the usual "alert" and "badge", but does not send the "sound". Consequently, my app plays the default alert sound for push notifications.
Is there any way to programmatically override the sound, so that I can play my own, custom remote push notification alert sound? Or even programmatically mute the sound? Remember, I cannot force the sending server to change the push notification payload to include a different sound.
I began by placing the sound file (ding.aiff) in my main bundle, but there seems to be no way of using that file in my app to play it instead of the default alert sound.
Does anyone know of a way using Swift 2+ on iOS8+ that can override or mute the remote push notification alert sound?
(If this is not possible - perhaps Apple is paranoid over music copyright - is there a way to mute the sound programmatically?)

start AVAudioSession & AVAudioPlayer in Background using didReceiveRemoteNotification:fetchCompletionHandler:

Can I play AVAudioPlayer when in the app is in background using silent push notification ?
My current implementation is like this :
Send silent push notification
didReceiveRemoteNotification:fetchCompletionHandler: is triggered
and create the session then play mp3 from there.
The issue is that the session seems to be taken away when your app is not active for quite a time (like one night) and AVAudioSession is not given if you request it from background mode, so the AVAudioPlayer won't play the mp3.
I'm developing an alarm app for emergency things, so the app need to play an audible sound even if the phone is muted and locked.
Anyone has been encountered any similar implementation?
The solution in your case would be to use "audio" setting from the UIBackgroundModes key, which effectively tells the system that the app's main purpose is to play music in the background: "The app plays audible content to the user or records audio while in the background". See this for details: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
However, it seems that Apple will reject "alarm apps" that use this approach as alarms do not play constantly and do not qualify as "audio apps". See this answer: Why did my app get rejected because "Multitasking apps may only use background"?.
You can try to "play" silence most of the time, but they will reject it either.
To summarize, you can implement this Alarm App technically, by using silent push notifications and UIBackgroundModes key, but this method is against Apple review policies.

Different tones in local notifications

I am developing a chat app. And of course, local notification is of great importance in such applications. So, I decided to take a look at the other chat apps to get an idea. Surprisingly, I found that WhatsApp and telegram have so much common alert tones. So the question is: Are the tones in whatsapp and telegram are system sounds? And if so, how to use them?
I did some search but found nothing regarding the topic!
When you send a remote notification to a device you can specify a notification sound.
As per the Apple docs the sound key should contain a string with:
The name of a sound file in the app bundle. The sound in this file is played as an alert. If the sound file doesn’t exist or default is specified as the value, the default alert sound is played. The audio must be in one of the audio data formats that are compatible with system sounds; see Preparing Custom Alert Sounds for details.
In case of a local notification you can set the property soundName to UILocalNotificationDefaultSoundName or any name of a sound file in the app bundle as well.
The notification sounds are located inside the app bundle. You *could* just unzip and explore the .ipa of the apps you mentioned.

Resources