-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathspeak_module.py
More file actions
61 lines (51 loc) · 1.79 KB
/
speak_module.py
File metadata and controls
61 lines (51 loc) · 1.79 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
import pyttsx3
import speech_recognition as sr
import pyaudio #pip install pipwin
#pipwin install pyaudio
# import os
# import pyaudio
# import speech_recognition as sr
from database import speak_is_on
from first_of_VA2 import *
import assistant_details
#choosing voice male [0] or female [1]
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[1].id)
def speak (usertext):
if speak_is_on():
engine.say(usertext)
engine.runAndWait()
else:
msg = QMessageBox()
msg.setWindowTitle(f"{assistant_details.name}")
msg.setText(f"{usertext}")
x = msg.exec_()
def get_audio():
r=sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source, duration=0.2)
msg = QMessageBox()
msg.setWindowTitle(f"{assistant_details.name}")
msg.setText(f"{assistant_details.name} : Listening.....")
x = msg.exec_()
print('Listening.....')
audio=r.listen(source)
said = ""
try:
print("Recognizing")
said = r.recognize_google(audio)
msg = QMessageBox()
msg.setWindowTitle("USER")
msg.setText(f" USER : {said}")
x = msg.exec_() # this will show our messagebox
print('USER: '+said)
#except Exception as e:
# print("Exception:(didn't get that) "+ str(e))
except sr.UnknownValueError:
print ('Google Speech Recognition could not understand')
return ('Google Speech Recognition could not understand')
except sr.RequestError :
print('Request error from Google Speech Recognition try checking your internet connection')
return said.lower()