How to get sound files in processing.py

edited August 2017 in Python Mode

I was looking at the forum as saw SoundFile() but this doesnt seem to work in python. Any ideas

Answers

  • I haven't confirmed that these are working, but see Minim Python Examples, the Minim (Sound) built-in Python example that comes with the mode, and the issue Playing Sound with Minim:

  • Ok, I got it to work - once. I loaded in the minim library and it does seem to work once the rectangle reaches the edge of the screen (this is where I want the noise to play). But it only seems to work once, and then never again.

    I also get JAVASOUND ERROR DONT KNOW THE ID3 CODE WXXX and DONT KNOW THE ID3 CODE TOPE

    Maybe this is why. Here is my code :

    add_library("minim")
    
    x1=100
    x2=25
    y1=0
    y2=25
    
    def setup():
        global sf
        size(200, 200)
        background(255) # white
        minim=Minim(this)
        sf=minim.loadFile("bounced.mp3")
    
    def draw():
        global x1,y1,x2,y2
        fill(155)
        rect(x1, y1, x2, y2)
    
    def keyReleased():
        global x1, y1, x2, y2
        rect(x1, y1, x2, y2)
        if (key == CODED):
            if (keyCode == LEFT) and x1>=0:
                x1=x1-10
                print(x1)
                background(255)
                rect(x1, y1, x2, y2)
    
    
            elif (keyCode == RIGHT) and x1<=170:
                x1=x1+10
                print(x1)
                background(255)
                rect(x1,y1,x2,y2)
    
            elif (keyCode == UP) and y1>=0:
                y1=y1-10
                print(y1)
                background(255)
                rect(x1,y1,x2,y2)
    
    
            elif (keyCode == DOWN) and y1<=170:
                y1=y1+10
                print(y1)
                background(255)
                rect(x1,y1,x2,y2)
    
            else:
                sf.play()
    
  • edited August 2017

    Sounds like your MP3 file has strange / invalid metadata -- ID3 is information (like artist, album, etc) in the MP3 file.

    https://en.m.wikipedia.org/wiki/ID3

    Are those both errors, or is one a warning?

    You might try using another short MP3 sample file from an official source instead and see if it works, or if the errors / warnings are unrelated to your play-only-once problem.

  • ok, I tried to find a really short mp3. I will look for a wave and another mp3 and see that help.
    Yes, the sound plays when they reach the edge of the screen.

  • edited August 2017

    I believe those are warnings. I have read in previous posts that you can find online web services where you can fix this missing/corrupted metadata in your mp3.

    ****EDIT: https://forum.processing.org/two/discussion/23182/how-do-i-disable-this-error-showing-up-in-console-don-t-know-the-id3-code-tbp/p1

    Kf

  • Will that fix the other problem of only playing the sound once? That is really the main issue

  • Try it! Use any valid MP3 file and see what happens.

  • I took the sound file that comes with windows and got the same error. I don't listen to music, so I don't have mp3 files. The program still did not play the music once I reached the edge of the screen - as before, it plays it once and never again.

  • Add sf.rewind() as your first line in keyReleased().

    Kf

  • I had to put the sf.rewind in the else statement. It doesn't work great, as in that it should ping immediately, there seems to be a delay. This is going to be put a damper on game design.

Sign In or Register to comment.