I have created a very simple voice assistant that listens to the user's input (more specifically, the user's story). Now, I want to create a function that stores the user's input - hereby, I have multiple questions:
- Do I need a dictionary or a dataframe?
- How do I write a function that stores the user's input (splitted into column A = timestamp and column B = user's input)?
- How do I write a function that creates a new row whenever there's a new user input?
This is my code so far:
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>= 0 and hour<12:
speak("Good Morning!")
elif hour>= 12 and hour<18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
assistantname =("Anna")
speak("I am your personal storykeeper " + assistantname)
#why doesn't this come right after "I am your personal storykeeper??"
def username():
speak("I would love to know more about you, so let's start off right away. What's your name?")
username = takeCommand()
speak("Nice to meet you " + username + ".")
print("Nice to meet you " + username + ".")
#columns = shutil.get_terminal_size().columns
#print("Welcome", username.center(columns))
def storykeepergoal():
speak("Would you like to know more about my goal to conserve your family's stories?")
query = takeCommand().lower() #All the commands said by user will be stored here in 'query' and will be converted to lower case for easily recognition of command
if "yes" in query:
speak("Happy that you are interested to learn more about me. You've probably experienced the moment at a family's birthday party when it's all about telling stories from when you were little, or a funny story about a vacation. As life goes on, those stories might be forgotten or cannot be told anymore. This is where I come in - by telling me stories about your favourite moments in life, I can store these forever. Your family can do the same thing. And if you would like to hear a story that your family members told me, you can tune in.")
print("Happy that you are interested to learn more about me. You've probably experienced the moment at a family's birthday party when it's all about telling stories from when you were little, or a funny story about a vacation. As life goes on, those stories might be forgotten or cannot be told anymore. This is where I come in - by telling me stories about your favourite moments in life, I can store these forever. Your family can do the same thing. And if you would like to hear a story that your family members told me, you can tune in.")
else:
speak("Alright, no problem.")
print("Alright, no problem.")
def getstory():
speak("I am curious to hear what memories and stories you have about your family. Please tell me your favourite memory with, or about your family.")
query = takeCommand().lower() #All the commands said by user will be stored here in 'query' and will be converted to lower case for easily recognition of command
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language ='en-GB')
print(f"User said: {query}\n")
except Exception as e:
print(e)
speak("My apologies, I did not understand that. Could you please say that again?")
print("My apologies, I did not understand that. Could you please say that again?")
return "None"
return query
wishMe()
username()
storykeepergoal()
getstory()
def append():
for query in story:
#df_story = pd.DataFrame(story)
new_row = {"timestamp": (now), "query": takeCommand()}
#df_story = df_story.append(new_row, ignore_index=True)
#return(df_story)
#print(df_story)
print(story)
append()