Skip to content

Commit

Permalink
Merge pull request #12 from TobiasDemuth/documentation-addition
Browse files Browse the repository at this point in the history
rewrote documentation added a little and seperated code
  • Loading branch information
TobiasDemuth authored Feb 13, 2024
2 parents 34a33d7 + a564e57 commit 9744924
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions speech_assistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
from tkinter import simpledialog
from translate import Translator

# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------

key = ""

# commands
search_commands = ["search"]
open_commands = ["open"]
math_commands = ["calculate"]
Expand All @@ -22,6 +28,7 @@
trans_commands = ["translate"]
zoom_commands = ["zoom","scale"]

# dictionarys
trans_dict = {
"german" : "de",
"france" : "fr",
Expand All @@ -32,17 +39,22 @@
"russian" : "ru"
}

# file names
app_file = "app_paths.txt"

def speech_to_text(language="en-EN"):
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------

def speech_to_text(language="en-EN"): # can be changed later also through code
recognizer = sr.Recognizer()

with sr.Microphone() as source:
audio = recognizer.listen(source)

try:
text = recognizer.recognize_google(audio, language=language)
print("you said:", text)
print("you said:", text) # just for debugging
return text
except sr.UnknownValueError:
return None
Expand All @@ -52,8 +64,8 @@ def speech_to_text(language="en-EN"):

def text_to_speech(response):
engine = pyttsx3.init()
engine.setProperty('rate', 200) # Ändern Sie die Sprechgeschwindigkeit nach Bedarf
engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0')
engine.setProperty('rate', 200) # speaking speach
engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0') # windows standart voice
engine.say(response)
engine.runAndWait()

Expand All @@ -67,10 +79,10 @@ def type_text(text):

def open_first_google_result(query):
try:
# Verwenden Sie die googlesearch-python-Bibliothek, um die ersten Suchergebnisse zu erhalten
# get first google-search link
search_results = search(query, num_results=1)

# Extrahieren Sie den ersten Link aus den Suchergebnissen
# extracting
first_link = next(search_results, None)

if first_link:
Expand Down Expand Up @@ -134,7 +146,7 @@ def delete_notes_with_keyword_from_csv(keyword):
matching_notes = df[df['Note'].str.lower().str.contains(keyword.lower())]

if not matching_notes.empty:
# Schreibe die verbleibenden Notizen (ohne die mit dem Schlüsselwort) zurück in die Datei
# reentering not keyword matching notes
df = df[~df['Note'].str.lower().str.contains(keyword.lower())]
df.to_csv(csv_file, index=False, encoding='utf-8')

Expand Down Expand Up @@ -181,6 +193,10 @@ def zoom_scale(user_input):
if user_input in ["out","down"]:
return pyautogui.hotkey('ctrl', '-')

# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------

def personal_assistant():
last_response = ""
app_paths = read_app_paths()
Expand Down Expand Up @@ -299,6 +315,8 @@ def personal_assistant():
file.write(f"{full_time} \t || \t {user_input} \t => \t {response}\n")
if datetime.now().strftime("%M") == "00" and datetime.now().strftime("%S") == "00" :
file.write("-----------------------------------------------------------------------------")




if __name__ == "__main__":
personal_assistant()

0 comments on commit 9744924

Please sign in to comment.