Skip to content

Commit 434399f

Browse files
authored
Merge pull request Python-World#512 from 19lyaejin/master
New Project (in subfolder): Speaking_Dictionary
2 parents 824f3d9 + 6eba86f commit 434399f

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Speaking Dictionary
2+
Speaking Dictionary is Python program that allows the user to find the meaning of English word by speaking it directly to the program(device). Then, the program(device) will directly explain the definition of the word out loud.
3+
4+
### Prerequisites
5+
pyttsx3: pip install pyttsx3
6+
PyDictionary: pip install PyDictionary
7+
speech recognition: pip install SpeechRecognition
8+
gTTS: pip install gtts
9+
10+
+pip install pyaudio
11+
12+
### How to run the script
13+
SpeakingDictionary.py
14+
15+
### Screenshot/GIF showing the sample use of the script
16+
[SpeakingDictionary](https://user-images.githubusercontent.com/69775935/140873415-dc79bdd7-d36e-4ca5-ae6f-4da88837f5f0.png)
17+
18+
### Author Name
19+
Yaejin Lee : 19lyaejin, https://github.com.19lyaejin
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import pyttsx3
2+
from PyDictionary import PyDictionary
3+
import speech_recognition as spr
4+
from gtts import gTTS
5+
import os
6+
7+
#Speaking class
8+
class Speak:
9+
def SpeakWord(self, audio):
10+
#Having initial constructor of pyttsx3
11+
pSpeakEngine= pyttsx3.init('sapi5')
12+
pVoices= pSpeakEngine.getProperty('voices')
13+
14+
#Speaking audio that got as parameter
15+
pSpeakEngine.setProperty('voices', pVoices[0].id)
16+
pSpeakEngine.say(audio)
17+
pSpeakEngine.runAndWait()
18+
19+
#Create Recognizer, Microphone instance
20+
sRecog= spr.Recognizer()
21+
sMic= spr.Microphone()
22+
23+
#Capture voice from microphone
24+
with sMic as source:
25+
print("Speak 'Hello' to initiate Speaking Dictionary!")
26+
print("----------------------------------------------")
27+
28+
sRecog.adjust_for_ambient_noise(source, duration= .2)
29+
rAudio= sRecog.listen(source)
30+
31+
szHello= sRecog.recognize_google(rAudio, language= 'en-US')
32+
szHello= szHello.lower()
33+
34+
#If you said 'Hello', initialize the speaking dictionary
35+
if 'hello' in szHello:
36+
sSpeak= Speak()
37+
pDict= PyDictionary()
38+
39+
print("Which word do you want to find? Please speak slowly.")
40+
sSpeak.SpeakWord("Which word do you want to find Please speak slowly")
41+
42+
try:
43+
sRecog2= spr.Recognizer()
44+
sMic2= spr.Microphone()
45+
46+
#Capture the word that the user want to find the meaning of
47+
with sMic2 as source2:
48+
sRecog2.adjust_for_ambient_noise(source2, duration= .2)
49+
rAudio2= sRecog2.listen(source2)
50+
51+
szInput= sRecog2.recognize_google(rAudio2, language= 'en-US')
52+
53+
try:
54+
#Make sure that the recognizer got the correct word
55+
print("Did you said "+ szInput+ "? Please answer with yes or no.")
56+
sSpeak.SpeakWord("Did you said "+ szInput+ "Please answer with yes or no")
57+
58+
sRecog2.adjust_for_ambient_noise(source2, duration= .2)
59+
rAudioYN= sRecog2.listen(source2)
60+
61+
szYN= sRecog2.recognize_google(rAudioYN)
62+
szYN= szYN.lower()
63+
64+
#If the user said 'yes' (When the recognizer got the correct word)
65+
if 'yes' in szYN:
66+
szMeaning= pDict.meaning(szInput)
67+
68+
print("The meaning is ", end="")
69+
for i in szMeaning:
70+
print(szMeaning[i])
71+
sSpeak.SpeakWord("The meaning is"+ str(szMeaning[i]))
72+
73+
#When the recognizer got the wrong word
74+
else: sSpeak.SpeakWord("I am sorry Please try again")
75+
76+
#When the recognizer couldn't understand the answer(yes or no)
77+
except spr.UnknownValueError: sSpeak.SpeakWord("Unable to understand the input Please try again")
78+
except spr.RequestError as e: sSpeak.SpeakWord("Unable to provide required output")
79+
80+
#When the recognizer couldn't understand the word
81+
except spr.UnknownValueError: sSpeak.SpeakWord("Unable to understand the input Please try again")
82+
except spr.RequestError as e: sSpeak.SpeakWord("Unable to provide required output")
83+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Speaking Dictionary Requirements
2+
### prerequisites: pyttsx3, PyDictionary, speech_recognition, gTTS, pyaudio
3+
4+
pyttsx3: pip install pyttsx3
5+
PyDictionary: pip install PyDictionary
6+
speech_recognition: pip install SpeechRecognition
7+
gTTS: pip install gtts
8+
pyaudio: pip install pyaudio

0 commit comments

Comments
 (0)