本文介绍了在 pyo 和 python 中播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 Python 的 pyo.我使用主页上的这些命令为 ubuntu 安装了 pyo:

sudo apt-get install libjack-jackd2-dev libportmidi-dev portaudio19-dev liblo-dev须藤 apt-get 安装 libsndfile-dev python-dev python-tk须藤 apt-get install python-imaging-tk python-wxgtk3.0git 克隆 https://github.com/belangeo/pyo.git光碟须藤 python setup.py install --install-layout=deb --use-jack --use-double

但是,当我尝试播放声音的第一个示例时:

>>>从 pyo 进口 *>>>s = 服务器().引导()>>>s.start()>>>sf = SfPlayer("path/to/your/sound.aif", speed=1, loop=True).out()

我收到这些错误:

>>>从 pyo 进口 *pyo 0.7.9 版(使用单精度)>>>s = 服务器().引导()ALSA lib pcm_dsnoop.c:614:(snd_pcm_dsnoop_open) 无法打开从站ALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) 无法打开从站ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) 未知 PCM 卡.pcm.rearALSA lib pcm.c:2267:(snd_pcm_open_noupdate) 未知 PCM 卡.pcm.center_lfeALSA lib pcm.c:2267:(snd_pcm_open_noupdate) 未知 PCM 卡.pcm.sideALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) 无法打开从站无法连接到服务器套接字 err = 没有这样的文件或目录无法连接到服务器请求通道jack 服务器未运行或无法启动表达式 'parameters->channelCount

有人可以帮忙吗?PS:我正在运行 ubuntu 15.10

解决方案

步骤 1. 您应该列出您的音频硬件:

from pyo import *打印(音频主机APIS:")pa_list_host_apis()pa_list_devices()print("默认输入设备:%i" % pa_get_default_input())print("默认输出设备:%i" % pa_get_default_output())

我的系统结果是:

音频主机APIS:索引:0,ID:8,名称:ALSA,设备数量:10,默认输入:9,默认输出:9index: 1, id: 7, name: OSS, num devices: 0, default in: -1, default out: -1音频设备:0: OUT, name: HDA Intel HDMI: 0 (hw:0,3), host api index: 0, default sr: 44100 Hz, delay: 0.005805 s1: OUT, name: HDA Intel HDMI: 1 (hw:0,7), host api index: 0, default sr: 44100 Hz, delay: 0.005805 s2: OUT, name: HDA Intel HDMI: 2 (hw:0,8), host api index: 0, default sr: 44100 Hz, delay: 0.005805 s3: OUT, name: HDA Intel HDMI: 3 (hw:0,9), host api index: 0, default sr: 44100 Hz, delay: 0.005805 s4: OUT, name: HDA Intel HDMI: 4 (hw:0,10), host api index: 0, default sr: 44100 Hz, delay: 0.005805 s5: IN, name: HDA Intel PCH: CS4208 Analog (hw:1,0), host api index: 0, default sr: 44100 Hz, delay: 0.005805 s6: OUT, name: HDA Intel PCH: CS4208 Digital (hw:1,1), host api index: 0, default sr: 44100 Hz, delay: 0.005805 s7: OUT, name: hdmi, host api index: , 默认sr: 44100 Hz, 延迟: 0.005805 s8:IN,名称:pulse,host api index:0,默认sr:44100 Hz,延迟:0.008707 s8:OUT,名称:pulse,host api index:0,默认sr:44100 Hz,延迟:0.008707 s9:IN,名称:默认,主机 api 索引:0,默认 sr:44100 Hz,延迟:0.008707 秒9: OUT, name: default, host api index: 0, default sr: 44100 Hz, delay: 0.008707 s默认输入设备:9默认输出设备:9

步骤 2. 选择首选设备.就我而言,设备 9 没问题.

from pyo import *s = 服务器(双工=0)s.setOutputDevice(9) # 使用上一步的设备s.boot()s.start()# 尝试播放声音a = 正弦(mul=0.01).out()

I am trying out the pyo for python. I installed the pyo for ubuntu using these commands from the homepage:

sudo apt-get install libjack-jackd2-dev libportmidi-dev portaudio19-dev liblo-dev
sudo apt-get install libsndfile-dev python-dev python-tk
sudo apt-get install python-imaging-tk python-wxgtk3.0
git clone https://github.com/belangeo/pyo.git
cd pyo
sudo python setup.py install --install-layout=deb --use-jack --use-double

Howerver when i try the very first example to Play a sound:

>>> from pyo import *
>>> s = Server().boot()
>>> s.start()
>>> sf = SfPlayer("path/to/your/sound.aif", speed=1, loop=True).out()

i get these errors:

>>> from pyo import *
pyo version 0.7.9 (uses single precision)

>>> s = Server().boot()
ALSA lib pcm_dsnoop.c:614:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1024:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2267:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1024:(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.

Can anyone help?PS: I am running ubuntu 15.10

解决方案

Step 1. You should list your audio hardware:

from pyo import *

print("Audio host APIS:")
pa_list_host_apis()
pa_list_devices()
print("Default input device: %i" % pa_get_default_input())
print("Default output device: %i" % pa_get_default_output())

On my system result is:

Audio host APIS:
index: 0, id: 8, name: ALSA, num devices: 10, default in: 9, default out: 9
index: 1, id: 7, name: OSS, num devices: 0, default in: -1, default out: -1
AUDIO devices:
0: OUT, name: HDA Intel HDMI: 0 (hw:0,3), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
1: OUT, name: HDA Intel HDMI: 1 (hw:0,7), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
2: OUT, name: HDA Intel HDMI: 2 (hw:0,8), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
3: OUT, name: HDA Intel HDMI: 3 (hw:0,9), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
4: OUT, name: HDA Intel HDMI: 4 (hw:0,10), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
5: IN, name: HDA Intel PCH: CS4208 Analog (hw:1,0), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
6: OUT, name: HDA Intel PCH: CS4208 Digital (hw:1,1), host api index: 0, default sr: 44100 Hz, latency: 0.005805 s
7: OUT, name: hdmi, host api index: , default sr: 44100 Hz, latency: 0.005805 s
8: IN, name: pulse, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
8: OUT, name: pulse, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
9: IN, name: default, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
9: OUT, name: default, host api index: 0, default sr: 44100 Hz, latency: 0.008707 s
Default input device: 9
Default output device: 9

Step 2. Choose preferred device. In my case device 9 is ok.

from pyo import *

s = Server(duplex=0)
s.setOutputDevice(9) # Use device from the previous step
s.boot()
s.start()
# Try to play sound
a = Sine(mul=0.01).out()

这篇关于在 pyo 和 python 中播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 22:46