Skript lässt sich nicht ausführen
Verfasst: Donnerstag 26. November 2020, 16:44
Hallo zusammen,
da ich meinen Sprachassistenten doch noch fertig bekommen habe, wollte ich ihn jetzt ausführen. Als ich aber das Skript mit einem Doppelklick öffnen wollte, hat sich ein Fenster geöffnet und sogleich wieder geschlossen. Mach ich das falsch oder stimmt was mit meinem Skript nicht?
da ich meinen Sprachassistenten doch noch fertig bekommen habe, wollte ich ihn jetzt ausführen. Als ich aber das Skript mit einem Doppelklick öffnen wollte, hat sich ein Fenster geöffnet und sogleich wieder geschlossen. Mach ich das falsch oder stimmt was mit meinem Skript nicht?
Code: Alles auswählen
def speak(audio):
pass #For now. We will write the conditions later.
import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices') #getting details of the current voice
engine.setProperty('voice', voice[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait() #Without this command, speech will not be audible to us.
if __name__=="__main__" :
speak("Hello World! Hope you all are doing well.")
import datetime
def wishme():
hour = int(datetime.datetime.now().hour)
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!")
speak("Welcome! Please tell me how may I help you")
import speechRecognition as sr
def takeCommand():
#It takes microphone input from the user and returns string output
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-in') #Using google for voice recognition.
print(f"User said: {query}\n") #User query will be printed.
except Exception as e: # print(e) use only if you want to print the error!
print("Say that again please...") #Say that again will be printed in case of improper voice
return "None" #None string will be returned
return query
import wikipedia
if __name__ == "__main__":
wishMe()
while True:
query = takeCommand().lower() #Converting user query into lower case
# Logic for executing tasks based on query
if 'wikipedia' in query: #if wikipedia found in the query then this block will be executed
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
elif 'open youtube' in query:
webbrowser.open("youtube.com")
elif 'open google' in query:
webbrowser.open("google.com")
elif 'play music' in query:
music_dir = 'D:\\Non Critical\\songs\\Favorite Songs2'
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[0]))
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Ma'am, the time is {strTime}")