2

I am trying to get pyttsx3 to say text, a variable, and then more text, but for some reason it ignores the 3rd input and moves on to the next line of text. Here is the code:

    elif "what is the weather" in query:
        replaced_temp = temp.replace('F', '')

        tts.say('In' + g.city, 'it is currently' + replaced_temp)
        tts.runAndWait()
        print("completed")

When I run the code it says, "In " and nothing else, it skips to the next line and prints completed.

I've tried to make seperate tts.say lines, seperating the speech into different parts and it works, there are just big pauses in between the lines of code.

  • What is the comma between two sentences for? – Selcuk Dec 16 '22 at 02:51
  • @Selcuk I put a comma after variables because it gives me an error otherwise, it says that the parenthesis is not closed. – Cason Wilson Dec 16 '22 at 03:01
  • That doesn't make any sense. You shouldn't put a comma because that makes the second part of your sentence a separate argument. Paste your original code so that we can see what the problem is. – Selcuk Dec 16 '22 at 03:02
  • The question is already solved, but all the tutorials I looked at said to put a comma after variables, and it solved errors. Thank you for letting me know though. – Cason Wilson Dec 16 '22 at 03:06

1 Answers1

4

Why not try using f-strings:

tts.say(f"In {g.city} it is currently {replaced_temp}")
U13-Forward
  • 69,221
  • 14
  • 89
  • 114