Hello there, i am working on an AI for a scholarship and i am connecting my app to my code in my computer using uplink. After connecting to uplink, the text to speech is not exactly working. the module I am using for text to speech is pyttsx3 . Usually to make my code say something, I type //speak(text)// , and when I run it, the text is spoken. The problem really starts when i use more than one of this speak function… Example-
// speak(“Hello, this is the first sentance”)
speak(“Hello, this is the second sentance”)//
The code works when i run it just as a python code but when i run this is anvil, it just says the first sentence and just stops but the app would be still running.
For the sake of simplicity, i have not shown the code of my AI instead i have shown just a small code featuring just the text to speech .
The python code in my system:
import pyttsx3 # pip install pyttsx3… the text to speech module
import anvil.server
anvil.server.connect(uplink key)
engine = pyttsx3.init(‘sapi5’)
voices = engine.getProperty(‘voices’)
engine.setProperty(‘voice’, voices[0].id)
def speak(text):
# This function will pronounce the string which u passed to it
engine.say(text)
engine.runAndWait()
engine.stop()
@anvil.server.callable
def say(): # the function i would be calling with anvil
speak("hello. testing. this is the first sentence")
speak("hello. this is the second sentence")
speak("hey. this is the third sentance")
anvil.server.wait_forever()
The Anvil code:
from ._anvil_designer import Form1Template
from anvil import *
import anvil.server
class Form1(Form1Template):
def init(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run when the form opens.
def button_1_click(self, **event_args):
anvil.server.call(“say”)
“”“This method is called when the button is clicked”""
pass
So, when button_1 is clicked, it should say the 3 sentences but as you know, it says the first sentance and just stops…does it have anything to do with the anvil.server.wait_forever function? Please help me with this problem… Thank You!!