質問

I have a GUI program written by Python+Panda3d. I want to add a sound which keeps playing during runtime. The frequency of the sound is constant, and the volume is determined by a variable and modified time by time.

What's the easiest way to implement this?

I've searched some audio libraries of Python, they seem to be complex though my desired feature is very simple. So I wonder whether there's an easier way.

Thanks.


Update: The program is for Windows.

役に立ちましたか?

解決

Well, there's no available answer yet, so let me report my own workaround.

  1. Generate a tone at the given frequency by a tone generator, then get the .wav file. Put the .wav file at an accessible path.

  2. Use the Panda3D's built-in sound function:

    base = ShowBase()
    mySound = base.loader.loadSfx("path/to/the_tone.wav")
    

    make it keep playing:

    mySound.setLoop(True)
    mySound.play()
    
  3. To adjust the volume, just call:

    mySound.setVolume(0.5) # 0.0~1.0 
    

This solution works perfectly. Thanks to Panda3D.

他のヒント

This video tutorial is very nice, working with gStreamer and frequencies: GNOME Screencasts Creating a posh guitar tuner https://vimeo.com/26100971

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top