Pyo server.boot() 在 Ubuntu 14.04 上失败并显示 pyolib._core.PyoServerStateException

Men*_*eni 5 python ubuntu python-2.7 ubuntu-14.04 pyo

我在没有插孔的情况下在 Ubuntu 14.04 上安装了 pyo 并运行 Python 2.7 。我按照 pyo wiki 中编写的基于 Debian 的安装说明进行操作。这是我使用的代码(在pyo 介绍页面中):

from pyo import *
s = Server().boot()
s.start()
a = Sine(mul=0.01).out()
Run Code Online (Sandbox Code Playgroud)

结果如下:

pyo version 0.6.8 (uses single precision)
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
Expression 'parameters->channelCount <= maxChans' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1514
Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection_In )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2818
portaudio error in Pa_OpenStream: Invalid number of channels
Portaudio error: Invalid number of channels
Server not booted.
The Server must be booted!
Traceback (most recent call last):
  File "/host/Python/Synth/synther.py", line 4, in <module>
    a = Sine(mul=0.01).out()
  File "/usr/lib/python2.7/dist-packages/pyolib/generators.py", line 58, in __init__
    PyoObject.__init__(self, mul, add)
  File "/usr/lib/python2.7/dist-packages/pyolib/_core.py", line 376, in __init__
    PyoObjectBase.__init__(self)
  File "/usr/lib/python2.7/dist-packages/pyolib/_core.py", line 262, in __init__
    raise PyoServerStateException("The Server must be booted before creating any audio object.")
pyolib._core.PyoServerStateException: The Server must be booted before creating any audio object.
Run Code Online (Sandbox Code Playgroud)

PS:对使用 jack 不感兴趣,已经有问题了。

Cir*_*四事件 0

可以在 Ubuntu 20.04 上运行了

在尝试了几件事并经历了很多挫折之后......以下工作有效:

sudo apt install python3-pyo
Run Code Online (Sandbox Code Playgroud)

和测试:

#/usr/bin/env python3
from pyo import *
s = Server()
s.boot()
s.start()
a = Sine(freq=440, mul=0.5)
a.out()
time.sleep(2)
a.stop()
s.stop()
Run Code Online (Sandbox Code Playgroud)

根据需要产生 2 秒 440Hz 正弦声音。也许需要重新启动。

如果启动测试时程序正在使用音频,例如 Chromium 播放 YouTube 视频或 VLC 播放音乐,那么它会因该异常而失败,因此请确保暂停/关闭所有此类应用程序。

另一件值得做的事情是:

sudo apt install python3-wxgtk4.0
Run Code Online (Sandbox Code Playgroud)

否则 pyo 每次都会发出有关缺少 wxWidgets 的警告。不过,我认为这不会导致运行失败。

上面sudo apt install python3-pyo安装了 pyo 1.0.0,以及它工作所需的所有二进制依赖项,依赖项由以下方式给出:

apt-cache depends python3-pyo
Run Code Online (Sandbox Code Playgroud)

是:

python3-pyo
  Depends: libc6
 |Depends: libjack-jackd2-0
  Depends: <libjack-0.125>
    libjack-jackd2-0
    libjack0
  Depends: liblo7
  Depends: libportaudio2
  Depends: libportmidi0
  Depends: libsndfile1
  Depends: python3
  Depends: python3
  Depends: <python3:any>
    python3:i386
    python3
  Recommends: python3-tk
  Recommends: jackd2
Run Code Online (Sandbox Code Playgroud)

现在,如果我尝试使用以下方法升级 pyo:

python -m pip instal --user pyo==1.0.X
Run Code Online (Sandbox Code Playgroud)

它优先于提供的发行版 1.0.0,我得到以下结果:

  • 1.0.0:有效

  • 1.0.1:有效

  • 1.0.2:因错误而爆炸:

    ALSA lib conf.c:3558:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/usr/lib/alsa-lib/libasound_module_conf_pulse.so: libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
    
    Run Code Online (Sandbox Code Playgroud)

    但后来我locate libasound_module_conf_pulse.so在我的系统上,并解决:

    sudo ln -s /usr/lib/x86_64-linux-gnu/alsa-lib /usr/lib/alsa-lib
    
    Run Code Online (Sandbox Code Playgroud)

    然后就可以了。

    我还在以下位置报告了这一点: https: //github.com/belangeo/pyo/issues/200

  • 1.0.3:相同

另一件值得尝试的事情是Playing sound in pyo and python

from pyo import *
print("Default input device: %i" % pa_get_default_input())
print("Default output device: %i" % pa_get_default_output())
print("Audio host APIS:")
pa_list_host_apis()
pa_list_devices()
Run Code Online (Sandbox Code Playgroud)

然后尝试使用以下命令选择特定设备:

s = Server()
s.setOutputDevice(0)
s.boot()
Run Code Online (Sandbox Code Playgroud)

但我不需要这样做才能在安装后使其正常工作python3-pyo

https://github.com/belangeo/pyo/issues/200#issuecomment-734958205解释了如何让这一切与 Jack 一起工作。