ich bin seit Ende letzter Woche dabei mir einen kleinen Sprachassistenten in Python zu basteln.
Momentan benutze ich zur Spracherkennung Speech Recognition.
Jetzt zu meiner Frage beziehungsweise meinem Problem.
Ich benutze momentan einfach nur viele if-Abfragen um zu überprüfen ob ein bestimmtes Schlüsselwort im Text enthalten ist.
Wenn dieses Wort enthalten ist dann wird ein bestimmter Teil des Codes abgespielt.
Da ich jedoch noch einige Features im Kopf habe welche ich gerne noch einbauen möchte denke ich, dass da noch einiges an Abfragen mit dazu kommen.
Gibt es irgendeinen Weg wie ich die Schlüsselwörter kompakter abfragen kann?
Also so, dass nicht immer alles einzeln Abgefragt werden muss?
Oder ist das schon die "ideale" Lösung?
Vielen Dank für eure Hilfe

Code: Alles auswählen
while True:
print("Listening")
text = get_audio()
if wake in text:
if text == wake:
say("Wie kann ich helfen?")
text = get_audio()
noteActivation = ["schreib", "notiz"]
for word in noteActivation:
if word in text:
say("Was soll ich aufschreiben?")
note_text = get_audio()
note(note_text)
programActivation = ["start", "öffne"]
for word in programActivation:
if word in text:
startProgram(text)
if "suche" in text:
search(text)
elif "spiele" and "von" in text:
track = text.split("spiele")[1]
track = track.split("von")[0]
artist = text.split()
artist = artist[-1]
spotify.playSongFromArtist(track, artist)
elif "spiele" in text:
spotify.playSong(text.split("spiele")[1])
elif "stop" in text:
spotify.stopSong()
elif "vorheriges" in text:
spotify.previousSong()
elif "neustart" in text:
config.read(settings_path)
elif "screenshot" in text:
myScreenshot = pyautogui.screenshot()
myScreenshot.save(r'C:\Users\Pictures\Screenshots\{}.png'.format(dateNow()))
say("Der Screenshot wurde gespeichert. Soll ich den Ordner öffnen?")
text = get_audio()
if text == "ja":
os.startfile(r'C:\Users\Pictures\Screenshots')
elif "einstellungen" in text:
os.startfile(settings_path)
elif ("e-mail" in text) or ("email" in text):
webbrowser.open("https://mail.google.com/mail/u/0/#inbox", new=2)
elif "speedtest" in text:
os.system("start cmd /k speedtest-cli")