Python openAL 3D 声音 [英] Python openAL 3D sound

查看:29
本文介绍了Python openAL 3D 声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用 python,我正在制作音频处理程序.我正在尝试在我的 python 应用程序中使用 openAL 实现 3D 声音,但我只能让它工作

I just started with python and I am making program for audio manipulation. I am trying to implement 3D sound with openAL in my python application, but I just can get it to work

这是我的 3D 声音代码:

this is my code for 3D sound:

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)

代码执行,但不播放声音

The code executes, but it doesn't play the sound

推荐答案

原来在 Bitbucket 存储库页面上有一些关于如何使用 PyAL 的示例 这里.基于 audioplayer.py 示例,我根据正弦波在左右耳机扬声器之间使用声音替代制作了这个令人讨厌的声音示例:

It turns out that there are some examples of how to use PyAL at the Bitbucket repository page here. Based off the audioplayer.py example, I made this annoying-sounding example with the sound alternative between the left and right headphone speaker according to a sine wave:

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

这篇关于Python openAL 3D 声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆