通过树莓派同时播放多个声音文件,最好使用python [英] Play Multiple sound files simultaneously through raspberry pi, preferably using python
问题描述
我正在尝试在树莓派上制作乐器,但这是我第一次使用它,所以有点棘手.在我为该乐器编写的程序中,我无法一次执行多个声音,我该怎么做呢?
I'm trying to make an instrument on the raspberry pi but it's my first time using one so it's a bit tricky. In the program that I'm writing for this instrument I'm having trouble executing multiple sounds at once, how would I go about doing that?
推荐答案
看起来已经有一些类似的问答集:
it looks like there are some similar Q&A's on stack already:
https://stackoverflow.com/a/34830968/6253693
https://stackoverflow.com/a/39644525/6253693
我也刚刚尝试了第三个可行的实现,请参见下面的代码:
I also just tried a third implementation that works, see code below:
import simpleaudio as sa
wave_obj = sa.WaveObject.from_wave_file("Downloads/sample1.wav")
wave_obj2 = sa.WaveObject.from_wave_file("Downloads/sample2.wav")
wave_obj.play()
wave_obj2.play()
一般的好习惯是在问一个重复的问题之前先进行一些搜索(我最近犯了同样的错误,尽管不用担心).
Generally good practice to do some searching before asking a repeated question (I recently made the same mistake though so no worries.)
这篇关于通过树莓派同时播放多个声音文件,最好使用python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!