omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Audio Generation with Screen Off

    Pythonista
    3
    6
    2117
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • apiarian
      apiarian last edited by

      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_disabled function, 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_effect function. Since it is an infinite stream, I can't just ask Pythonista to play an infinitely long file.

      stephen 1 Reply Last reply Reply Quote 0
      • stephen
        stephen @apiarian last edited by stephen

        @apiarian personally never used sound module though i should. try this thread some comments seem to be about your situation. omz shows a solition to play forever

        GOOD LUCK!

        Example:

        
        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()
        
        1 Reply Last reply Reply Quote 0
        • stephen
          stephen last edited by

          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

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by

              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
              https://forum.omz-software.com/topic/5155/real-time-audio-buffer-synth-real-time-image-smudge-tool

              Which talks about both some high performance graphics techniques, and some high performance audio techniques.

              1 Reply Last reply Reply Quote 0
              • stephen
                stephen last edited by

                @apiarian while researching objc i found this seems lik it should help

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors