-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary.py
33 lines (31 loc) · 913 Bytes
/
dictionary.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
import datetime
import time
import speech_recognition as sr
import pyttsx3
import os
import subprocess
r = sr.Recognizer()
# Function to convert text to
# speech
def SpeakText(command):
# Initialize the engine
engine = pyttsx3.init()
engine.say(command)
engine.runAndWait()
from PyDictionary import PyDictionary
SpeakText("opening dictionary ....... say exit to close dictionary")
dictionary=PyDictionary()
while(1):
try:
with sr.Microphone() as source2:
SpeakText("Which word you want to know meaning?")
r.adjust_for_ambient_noise(source2, duration=0.2)
audio2 = r.listen(source2)
word = r.recognize_google(audio2)
if(word=="exit"):
break
print(word)
SpeakText(dictionary.meaning(word))
except sr.UnknownValueError:
SpeakText("Sorry!! Invalid Command")
SpeakText("Thanks for using dictionary")