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.


    How to repeat sound?

    Pythonista
    6
    5
    4253
    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.
    • upwart
      upwart last edited by

      I would like to play a sound continously (until a certain event).
      I know to use sound.play_effect, but how can I issue another play_effect when the sound is over (basically, all I need to know is when the effect is over.

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

        There appears to be no kind of function to test if a sound is playing, and it isn't possible to tell the sound.play_effect() function to wait for the sound to stop. If you know the sound's length, you can use time.sleep() as shown in the example in the sound module docs. As long as you're not trying to execute code while the sound is playing it should work fine, because time.sleep() will stop the entire script while the sound is played. Not sure if Python has any kind of threading support, as that would probably be necessary in that case.

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

          There's a currently undocumented Player class in the sound module that allows (among other things) to loop sounds:

          Here's a simple demo of how you can use it:

          https://gist.github.com/omz/10023837

          Note that the Player class works with file paths instead of built-in sound effect names, so I'm using os.path.expanduser() to get at the underlying .caf file of the built-in 'Beep' effect.

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

            In case anybody else is dredging the forums trying to figure out how the sound module works, sound.play_effect() actually takes up to 5 parameters. The last one makes it repeat:

             effect = sound.play_effect('my_sound.wav', volume, pitch, unknown, repeat)
            

            If repeat is anything that evaluates to True, the sound seems to repeat until you call sound.stop_effect(effect).

            I have no idea what the unknown parameter does.

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

              See off-line doc, all parameters are explained (select play_effect and tap help)

              As @dgelessus said in Speech/Sound Module Q's topic

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