Audio Generation with Screen Off
I've written a tool that generates and plays an infinite stream of music. Currently by riffing on Satie's Gnossiennes 1. It's fun! https://github.com/apiarian/twisted_music/blob/master/infinite_gnossiennes_1.py (inspired by Mouse Reeve's Infinite Gnossienne https://github.com/mouse-reeve/infinite_gnossienne ).
It works pretty well, but it only works while the screen is on or the app is on at least a part of my screen on my iPad. I've got a context manager which prevents device sleep with the
console.set_idle_timer_disabledfunction, but it would be really nice to just let this run in the background.
Since this is a musical use-case, is there a way to convince iOS to let it run in the background with the screen off indefinitely?
The app currently works by taking an infinite generator (doesn't have to be infinite, but in this case it is) of sound description objects, chunking them up and building temporary WAV files, and playing them with the appropriate delays, one after the other (sometimes overlapping slightly as necessary) using the
sound.play_effectfunction. Since it is an infinite stream, I can't just ask Pythonista to play an infinitely long file.
omz: "You don't really need objc_util for this, it should work with the sound module as well." import sound import os import urllib # download a silent mp3 if it's not there yet: if not os.path.exists('silence.mp3'): urllib.urlretrieve('http://www.xamuel.com/blank-mp3-files/1sec.mp3', 'silence.mp3') player = sound.Player('silence.mp3') player.number_of_loops = -1 # repeat forever player.play() # do background stuff... # when you're done: player.stop()
with a little further looking into this i found this from Apple. notbsaying this will fix your issue but if its not because pythonista it should help
There were a few betas that enabled background audio, but I believe made omz remove that entitlement (that was a way to allow infinite background processing good for us, but apple is very protective about that)
The best you can do is disable the idle timer, so screen always stays on (and keep it plugged in). see console module.
By the way, you can get infinite smooth sounds without gapping (don't have to make temporary wav files) by using some low level audio functions. For an in depth discussion, see this thread
Which talks about both some high performance graphics techniques, and some high performance audio techniques.