Hi I'm new to python and I'm making a voice assistant.
The Voice string contains what I've said using speech.recognition.
I was thinking to split the Voice string into a list and return the string that match.
For example: Voice = "Hi, could you research this and that on google"
I asked it in a different way, but I think I didn't ask properly what I was looking for. How to use any string from list as a variable?
Voice_List = Voice.split()
List_A = ["research", "search"]
List_B = ["on google", "using google", "with google"]
Word_A = any_word in Voice_List AND in List_A
Word_B = any_word in Voice_List AND in List_B
webbrowser.get().set(anything between Word_A and Word_B)
I think in this case you can specify your voice list as a set as well as your list_a or list_b as another set. Then you can apply the intersection function directly.
Voice_Set = set(Voice.split())
Set_A = set(["research", "search"])
Set_B = set(["on google", "using google", "with google"])
Word_A = Voice_Set.intersection(Set_A)
Word_B = Voice_Set.intersection(Set_B)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.