-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice.py
More file actions
90 lines (75 loc) · 3.04 KB
/
voice.py
File metadata and controls
90 lines (75 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import time
import speech_recognition as sr
import pyttsx3
import speech
import features
phrase = 'hey darwin'
# Initialize the recognizer
r = sr.Recognizer()
# Function to convert text to
# speech
def SpeakText(command):
# Initialize the engine
engine = pyttsx3.init()
engine.say(command)
engine.runAndWait()
# Loop infinitely for user to
# speak
speech.stock_voice()
speech.config_test()
while 1:
# Exception handling to handle
# exceptions at the runtime
try:
# use the microphone as source for input.
with sr.Microphone() as source2:
# wait for a second to let the recognizer
# adjust the energy threshold based on
# the surrounding noise level
r.adjust_for_ambient_noise(source2, duration=0.2)
# listens for the user's input
audio2 = r.listen(source2)
# Using google to recognize audio
MyText = r.recognize_google(audio2)
MyText = MyText.lower()
print(MyText)
if phrase + " weather" in MyText or "temperature" in MyText:
SpeakText(features.weather('California, US', 'celsius'))
elif phrase + ' news' in MyText:
features.npr()
elif phrase + ' search' in MyText:
SpeakText('Hello due to issues beyond my control i cannot use a search engine resolution, using gpt4all')
time.sleep(2)
SpeakText('What would you like to search for? ')
time.sleep(1)
search_queue = r.listen(source2)
search_queue = r.recognize_google(search_queue)
search_results = features.search(search_queue,"mistral-7b-instruct-v0.1.Q4_0.gguf")
# prompt_satisfied = False
# search_num = 0
# while prompt_satisfied != True:
# SpeakText('What Would You Like To Search For ?' )
# search_queue = r.listen(source2)
# search_queue = r.recognize_google(search_queue)
# search_results = features.search(search_queue,search_num)
#
# SpeakText(search_results[0])
# time.sleep(2)
# SpeakText(search_results[1])
# time.sleep(2)
# SpeakText('Would You Like to hear from a different source? ')
# check_prompt = r.listen(source2)
# check_prompt = r.recognize_google(check_prompt)
# if 'no' in check_prompt:
# prompt_satisfied = True
# elif 'yes' in check_prompt:
# search_queue += 1
elif "hey darwin" not in MyText:
print("Did you say ", MyText)
SpeakText(MyText)
# else:
# SpeakText('Hello My name is darwin I dont do much yet but I hope to be of great use')
except sr.RequestError as e:
continue
except sr.UnknownValueError:
continue