How to play a Downloaded Audio-file, automatically

Thank you Robert and sc459 but i don’t that wouldn’t be necessary… but i just had a crazy idea and started from square one with pyttsx3 (no specific reasons)… I used a completely different structure and IT WORKED!!!.Here is the code-
The actual need for this project was for my AI, so you might notice some changes in the code below-
(server code)

import pyttsx3
import anvil.server

anvil.server.connect("<uplink_key>")

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
@anvil.server.callable()
def say(text):
    # This function will pronounce the string which u passed to it
    engine.say(text)
    engine.runAndWait()
@anvil.server.callable()
def speak():
    i="hello"                         # This is how I actually wanted the text to be for the AI
    f= "I am baymax"
    return i,f;
anvil.server.wait_forever()

(client 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):
    
    w=anvil.server.call("speak")
    anvil.server.call("say",w)
    """This method is called when the button is clicked"""
    pass

If you were wondering that this is a whole new code and doesn’t even relate to the topic, it was because, when i was just sending a text to the speak function to speak, it would work as a python code but not with anvil;it would stop working after the first time i called the function. So with the help of David and Campopianoa, we came up with a totally different code using GTTS which sent an audio-file to anvil…and you know the rest.

So, anyway, thank you sc549,robert and david, for helping me out.

1 Like