0

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)

    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="")
namnam
  • 19
  • 2

1 Answers1

1

Try the built in module, threading:

from threading import Thread
import winsound

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

Sound = Thread(target=sound)

Sound.start()
print("-")
Red
  • 26,798
  • 7
  • 36
  • 58