简体   繁体   English

如何使用 winsound 模块同时播放多个频率

[英]How to play multiple frequencies simultaneously using the winsound module

I am creating a simple music playing program using the Beep function in the winsound module.我正在使用winsound模块中的Beep功能创建一个简单的音乐播放程序。 I am trying to play multiple "Beeps" at once, trying things such as我正在尝试一次播放多个“哔哔声”,尝试诸如

from winsound import Beep
Beep(440, 2000) + Beep(330, 2000)

and

from winsound import Beep
Beep(440, 2000), Beep(330, 2000)

but none of them work.但它们都不起作用。 I know this probably has a really simple answer, but I would really appreciate some help.我知道这可能有一个非常简单的答案,但我真的很感激一些帮助。 Thanks!谢谢!

Try this尝试这个

import winsound  
from multiprocessing import Process
def func1():
     winsound.PlaySound("C:\samplepath\soundfile1.wav", winsound.SND_FILENAME|winsound.SND_NOWAIT)

def func2():
     winsound.PlaySound("C:\samplepath\soundfile2.wav", winsound.SND_FILENAME|winsound.SND_NOWAIT)

if __name__=='__main__':
     p1 = Process(target = func1)
     p1.start()
     p2 = Process(target = func2)
     p2.start()

This should allow you to play sounds simultaneously (although I have not tested it with beeps).这应该允许您同时播放声音(虽然我没有用哔哔声测试过它)。

I can not play with winsound at this monment, but guessing you can use threading module to achieve your goal, like this:我不能玩winsound在这个monment,但猜你可以使用threading模块来实现自己的目标,就像这样:

from winsound import Beep
import threading

# Start multi threads, so `Beep` will run simultaneously instead of blocking
threading.Thread(target=Beep, args=(440, 2000)).start()
threading.Thread(target=Beep, args=(330, 2000)).start()

For more details on the threading module, you can go to the document .关于线程模块的更多细节,你可以去文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM