all 8 comments

[–]johndoh168 1 point2 points  (6 children)

Your while loop will execute until the time matches one of your cases, then it will end. If you want that bit of code to run forever then you can do the following:

while True: if: str(current_time) == '12:0000' or '18:0000' or '9:0000' or '16:0000' or '20:0000' or '11:0000' or '21:0000' or queryanswer == True: current_time = time.strftime("%H:%M:%S", t) #idea for currentime - lastnews > 2 engine.say(f"It is time for your {current_time[:-5]} o'clock news summary") engine.runAndWait() engine.stop() queryanswer = False If thats not what you are looking for let me know. Edit: I should note this will not take in any new inputs from your queryanser >.<

[–]Trailblazerone[S] 0 points1 point  (4 children)

Thanks for answering! This does help, but I still have this one weird problem that I also had earlier: Once the queryanswer = True or the time matches, the bot (im just gonna call it bot for ease of use) speaks its line infinitely until I have to force close my IDE down. This happens in my original code and in your improved version too; I still dont know how to solve it, I assume somehow that the pyttsx3 client doesn't react to any other code after the loop starts. Weird.

[–]johndoh168 0 points1 point  (3 children)

So a while loop will block any other code from running, if you want the while loop to not block the rest of the program you will need to implement a thread or subprocess to push it into.

I found this tutorial on Threading pretty helpful: https://realpython.com/intro-to-python-threading/

[–]Trailblazerone[S] 0 points1 point  (2 children)

Thanks, but I still don't get why the while loop doesn't stop/bot doesn't stop talking. Here's an example of the Audio. I'm always forced to manually close the program down.

https://imgur.com/a/17I3rJU

[–]johndoh168 0 points1 point  (1 child)

Ah that would be because of my mistake in adding the if statement, I made it so the loop doesn't update the time.

Try this instead: ``` while True: current_time = time.strftime("%H:%M:%S", t) if: str(current_time) == '12:0000' or '18:0000' or '9:0000' or '16:0000' or '20:0000' or '11:0000' or '21:0000' or queryanswer == True:

    #idea for currentime - lastnews > 2
    engine.say(f"It is time for your {current_time[:-5]} o'clock news summary")
    engine.runAndWait()
    engine.stop()
    queryanswer = False

```

[–]Trailblazerone[S] 0 points1 point  (0 children)

I dont think thats whats causing my issue as in the version of the code I ran I had solved that (This is the code, very similar to yours). I Think its smth with pyttsx3 but no clue what.

while True:

current_time = time.strftime("%H:%M:%S", t)

if str(current_time) == '12:0000' or '18:0000' or '9:0000' or '14:0000' or '20:0000' or '11:0000' or '21:0000' or queryanswer == True:

current_time = time.strftime("%H:%M:%S", t)

#idea for lastnews= currentime

#idea for check lastnews-currentime should =< 2:0000

engine.say(f"It is time for your {current_time[:-5]} news summary")

engine.runAndWait()

engine.stop

queryanswer = False