简体   繁体   English

如何同时打印和播放声音? (温声)

[英]How can i print and play sound at the same time? (winsound)

I'm trying to make a morse code machine that plays the beep and then prints the morse code.我正在尝试制作一个播放哔哔声然后打印莫尔斯电码的莫尔斯电码机器。 Instead, it plays all the sounds and only then prints the message.相反,它会播放所有声音,然后才打印消息。 pls help.请帮忙。 code: (lettr2morse is a dictionary that has letters turned into morse)代码:(lettr2morse 是一本将字母变成莫尔斯的字典)

    morse_counter2 = 0
    morse_counter = 0
    morse_input = input("\nwhat would you like to tarnslate?\n")
    for r in range(len(morse_input)):
        morse = letter2morse.get(morse_input[morse_counter])
        for r in range (len(morse)):
            if morse[morse_counter2] == "-":
                winsound.Beep(750, 500)
                print("-", end="")
            else:
                winsound.Beep(750, 150)
                print(".", end="")
            morse_counter2 += 1
        time.sleep (1.5)
        morse_counter += 1
        morse_counter2 = 0
        print(" ", end="")

Try the built in module, threading :尝试内置模块threading

from threading import Thread
import winsound

def sound():
    winsound.Beep(750, 500)

Sound = Thread(target=sound)

Sound.start()
print("-")

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

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