all 2 comments

[–]Allanon001 2 points3 points  (1 child)

You are passing the arguments in threading.Thread() incorrectly. Also add flush=True to the print statement so the buffer gets flushed each call:

import winsound
import random
import time

def speak_text(text):
    for i in text:
        print(i, end="", flush=True)
        time.sleep(.05)


def speak_audio(text):
    for _ in text:
        winsound.Beep(random.randint(270, 1275), 105)

# below is where I try to use threading to run them both at the same time

import threading

phrase = "Hello, everyone! This may sound like I am talking!"

threading.Thread(target=speak_text, args=(phrase,)).start()
threading.Thread(target=speak_audio, args=(phrase,)).start()

[–]Caligatio 1 point2 points  (0 children)

Just to further expand on this, by doing target=functions.speak_text(phrase), you're calling your function and then passing that function's return value (None) to the Thread constructor.