我在Python 2.7.14中使用Pyo(http://ajaxsoundstudio.com/software/pyo/),并且尝试使用此代码播放音频文件

from pyo import *
s = Server()
s.boot()
s.start()
sf  = SfPlayer("C:\Users\name\Downloads\audio.mp3", speed=1, loop=True).out()

但我收到此消息:
Traceback (most recent call last):
  File "C:\Python27\pyotest.py", line 5, in <module>
    sf  = SfPlayer("C:\Users\name\Downloads\audio.mp3", speed=1, loop=True).out()
  File "C:\Python27\lib\site-packages\pyolib\players.py", line 98, in __init__
    PyoObject.__init__(self, mul, add)
  File "C:\Python27\lib\site-packages\pyolib\_core.py", line 967, in __init__
    PyoObjectBase.__init__(self)
  File "C:\Python27\lib\site-packages\pyolib\_core.py", line 809, in __init__
    raise PyoServerStateException("The Server must be booted before "
PyoServerStateException: The Server must be booted before creating any audio object.

最佳答案

我曾经有过相同的错误(在Windows上)。启动了安装Pyo附带的E-Pyo编辑器。之后,它工作正常。

如果这样做没有帮助,您可能需要手动设置服务器选项和输出设备。

使用以下命令获取所需输出设备的ID

pa_list_devices()

如果找到了ID,则可以使用以下命令进行设置(将0更改为设备ID),然后启动服务器:
s.setOutputDevice(0)
s.boot()

关于python - 创建任何音频项目之前,必须先引导Python 2.7和Pyo,Server,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51958667/

10-11 09:08