Example #1
0
class Sara:
    def __init__(self):
        # Initializing speech recognition engine
        self.speech_recognition_object = RecognizeSpeech()

        # Initializing TTS engine
        self.speak_object = Speak()

    def listen(self):
        """
        This function returns decoded speech
        :return:
            (str) speech : The decoded speech.
        """
        speech = self.speech_recognition_object.recognize_speech()
        return speech

    def speak(self, text):
        """
        Converts text to speech and speaks aloud
        :param text: The text to speak.
        """
        self.speak_object.speak(text)

    def get_time(self):
        """
        :return: (str) Current time in 12 hour format.
        """
        time = datetime.now()
        if time.hour < 12:
            time = (str)(time.hour) + ":" + (str)(time.minute) + " AM"
        else:
            time = (str)(time.hour) + ":" + (str)(time.minute) + " PM"
        return time

    def generate_greetings(self):
        """
        Generates greetings based upon time.

        :return: (str) Greetings.
        """
        greetings = "Good "
        time = datetime.now()
        if time.hour >= 0 and time.hour < 12:
            greetings = greetings + "Morning"
        elif time.hour >= 12 and time.hour < 18:
            greetings = greetings + "Afternoon"
        elif time.hour >= 18 and time.hour <= 24:
            greetings = greetings + "Night"
        return greetings

    def introduction(self):
        """
        :return: (str) Introduction speech with greetings.
        """
        text = "Hi, " + self.generate_greetings() + "."
        text = text + " I am Sara, and how can I help you?\n"
        return text
Example #2
0
from speak import Speak

client = Speak()
client.speak("Hello")  # Remove the Hello string with any other string ##


#eg:
def input_speak(name):
    client.speak(f"Hi {name}")


#use the function like:
name1 = input("What's your name?: ")
input_speak(name1)