Python openAL 3D声音

时间:2016-04-11 17:58:05

标签: python audio 3d openal

我刚开始使用python,我正在为音频操作制作程序。 我试图在我的python应用程序中使用openAL实现3D声音,但我可以让它工作

这是我的3D声音代码:

from openal.loaders import load_wav_file
from openal.audio import *

sink = SoundSink()   
listener = SoundListener()
SoundSink.activate(sink)
listener.position = (0, 0, 0)
listener.velocity = (0, 0, 0)
listener.orientation = (0, 0, -1, 0, 1, 0)
source = SoundSource()
wavsound = load_wav_file("test.wav")
source.queue(wavsound)
#SoundSink.play(source)
sink.play(source)

代码执行,但它没有播放声音

1 个答案:

答案 0 :(得分:1)

事实证明,在Bitbucket存储库页面here中有一些如何使用PyAL的示例。基于audioplayer.py示例,我根据正弦波在左右耳机扬声器之间进行声音替换,制作了这个令人讨厌的例子:

import time
import math
from openal.audio import SoundSink, SoundSource
from openal.loaders import load_wav_file

if __name__ == "__main__":
    sink = SoundSink()
    sink.activate()
    source = SoundSource(position=[0, 0, 0])
    source.looping = True
    data = load_wav_file("./sounds/Blip_Select.wav")
    source.queue(data)
    sink.play(source)
    t = 0
    while True:
        x_pos = 5*math.sin(math.radians(t))
        source.position = [x_pos, source.position[1], source.position[2]]
        sink.update()
        print("playing at %r" % source.position)
        time.sleep(0.1)
        t += 5