gpt4 book ai didi

python - 使用 Pyo 在 Python 中播放声音

转载 作者:行者123 更新时间:2023-12-02 23:07:15 25 4
gpt4 key购买 nike

我正在尝试使用 pyo 库播放声音。

以下代码:

from psychopy import sound, logging, core
logging.console.setLevel(logging.DEBUG)
from pyo import *

s = Server()
s.setInputDevice(4)
s.setOutputDevice(4)
s.boot()
s.start()

print "output", pa_get_output_devices()
print "input", pa_get_input_devices()

play_audio1 = sound.SoundPyo(value = 'LRsound.wav', stereo = True)
play_audio1.play()
core.wait(1) # wait so the sound can play

返回此输出:

pyo version 0.8.0 (uses single precision)

Portmidi warning: could not open midi output 0 (Microsoft MIDI Mapper): PortMidi: `Host error'

output (['Microsoft Sound Mapper - Output', 'Speakers / Headphones (Realtek ', 'Primary Sound Driver', 'Speakers / Headphones (Realtek High Definition Audio)', 'Realtek ASIO', 'Speakers / Headphones (Realtek High Definition Audio)'], [0, 1, 2, 3, 4, 5])

input (['Realtek ASIO'], [4])

Server not booted. The Server must be booted! portaudio error in Pa_OpenStream: Illegal combination of I/O devices Portaudio error: Illegal combination of I/O devicesportaudio error in Pa_AbortStream: Invalid stream pointer portaudio error in Pa_CloseStream: Invalid stream pointer



正如您从代码和输出中看到的那样,我试图确保输入和输出设备相同。

这是由于有关 I/O 设备非法组合的消息。当然,你也可以看到我的尝试失败了。无论是否使用 Server(),都会出现相同的错误消息。代码块。

我在 PsychoPy 中运行了上面的代码。当我在 Spyder 中运行相同的代码时,它实际上从未通过:
play_audio1 = sound.SoundPyo(value = 'LRsound.wav', stereo = True)

它只是挂起无所事事。

知道为什么 pyo 没有像它应该玩的那样玩 python 吗?关于如何修复它的任何想法?

谢谢你的时间。

最佳答案

你必须 boot() Server在做任何其他事情之前,所以你的行应该是:

import pyo

s = pyo.Server()
s.boot()
s.start()
s.setInputDevice(4)
s.setOutputDevice(4)

然后你可以使用 SfPlayer来自 pyo 的类(class)播放声音文件:
play_audio1 = pyo.SfPlayer(path="LRsound.wav", speed=[1, 1])
play_audio1.out()

并运行 gui 界面:
s.gui(locals(), exit=False)

关于python - 使用 Pyo 在 Python 中播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40774534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com