-
Notifications
You must be signed in to change notification settings - Fork 4
/
WordWizard.py
45 lines (40 loc) · 1.37 KB
/
WordWizard.py
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
# Importing Modules
import speech_recognition as sr
import pyautogui
import threading
from deepmultilingualpunctuation import PunctuationModel
# Initializing the Punctuator Engine
model = PunctuationModel()
# Setup Speech Listener
r = sr.Recognizer()
# Function for Continual Listening
def listen():
with sr.Microphone() as source:
while True:
print("Listening...")
audio = r.listen(source)
print("Recognizing...")
try:
# Recognise using google engine
text = r.recognize_google(audio)
# code to stop typing
if "end typing code confirm" in text:
text=text.replace("end typing code confirm","")
t2 = threading.Thread(target=type_text, args=(text,))
t2.start()
break
# Starting Punctuate & Type
t2 = threading.Thread(target=type_text, args=(text,))
t2.start()
except sr.UnknownValueError:
pass
except sr.RequestError as e:
pass
# Function for Punctuating & Typing the Text
def type_text(text):
punctuated_text = model.restore_punctuation(text)
pyautogui.typewrite(punctuated_text,0.1)
# Starting the Listener Thread
# def start_typing():
t1 = threading.Thread(target=listen)
t1.start()