Playing Sound In Pyo And Python
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 l
Solution 1:
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:9index:1,id:7,name:OSS,num devices:0,default in:-1,default out:-1AUDIO devices:0:OUT,name: HDA Intel HDMI:0(hw:0,3),host api index:0,default sr:44100Hz,latency:0.005805s1:OUT,name: HDA Intel HDMI:1(hw:0,7),host api index:0,default sr:44100Hz,latency:0.005805s2:OUT,name: HDA Intel HDMI:2(hw:0,8),host api index:0,default sr:44100Hz,latency:0.005805s3:OUT,name: HDA Intel HDMI:3(hw:0,9),host api index:0,default sr:44100Hz,latency:0.005805s4:OUT,name: HDA Intel HDMI:4(hw:0,10),host api index:0,default sr:44100Hz,latency:0.005805s5:IN,name: HDA Intel PCH:CS4208Analog(hw:1,0),host api index:0,default sr:44100Hz,latency:0.005805s6:OUT,name: HDA Intel PCH:CS4208Digital(hw:1,1),host api index:0,default sr:44100Hz,latency:0.005805s7:OUT,name:hdmi,host api index:,default sr:44100Hz,latency:0.005805s8:IN,name:pulse,host api index:0,default sr:44100Hz,latency:0.008707s8:OUT,name:pulse,host api index:0,default sr:44100Hz,latency:0.008707s9:IN,name:default,host api index:0,default sr:44100Hz,latency:0.008707s9:OUT,name:default,host api index:0,default sr:44100Hz,latency:0.008707sDefault input device:9Default 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()
Solution 2:
Got it working on Ubuntu 20.04
After trying several things and a lot of frustration... the following worked:
sudo apt install python3-pyo
and the test:
#/usr/bin/env python3from pyo import *
s = Server()
s.boot()
s.start()
a = Sine(freq=440, mul=0.5)
a.out()
time.sleep(2)
a.stop()
s.stop()
produces a 2 second 440Hz sine sound as desired. Maybe a reboot was needed.
The Ubuntu package must be installing some missing binary dependencies, without which pyo
was throwing PyoServerStateException
.
More details at: Pyo server.boot() fails with pyolib._core.PyoServerStateException on Ubuntu 14.04
Post a Comment for "Playing Sound In Pyo And Python"