Skip to content

Commit 84a4c65

Browse files
committed
Setting up Environment and adding code
1 parent 4bd5f58 commit 84a4c65

File tree

6 files changed

+269
-0
lines changed

6 files changed

+269
-0
lines changed

prescription_generator/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Automated Voice based Prescription Generator
2+
3+
## Use Case:
4+
Generates Prescriptions in the form of PDF Files by recognizing the voice from doctors. This process will remove a lot of manual works and human errors as well as useful for the cases where doctor can't prescribe medicines physically.
5+
6+
## Features:
7+
* Input information through voice.
8+
* Control instructions through voice inputs.
9+
* Generates simply formatted PDF as Output.
10+
* Auto Noice Adjustment.
11+
* Exceptions Handling.
12+
13+
## Technologies used:
14+
* Python
15+
* Speech Recognition
16+
* Text to PDF Convertion
17+
18+
## Steps to run locally:
19+
<br>
20+
21+
1. clone the repository
22+
2. cd automated_voice_prescription_generator
23+
3. pip install -r requirements.txt
24+
4. python main.py
25+
5. Terminate the code anytime by saying 'exit'
26+
## Errors:
27+
* Incase you face issues related to **PyAudio**, run the below commands:
28+
29+
pip install pipwin
30+
pipwin install pyaudio
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# from .pdf_operations import save_pdf
2+
# from .speech import speech_rec_for_windows, speech_rec_for_linux
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from fpdf import FPDF
2+
3+
4+
class PDF(FPDF):
5+
def footer(self):
6+
# Position at 1.5 cm from bottom
7+
self.set_y(-15)
8+
# Arial italic 8
9+
self.set_font('Arial', 'I', 8)
10+
# Text color in gray
11+
self.set_text_color(128)
12+
# Page number
13+
self.cell(0, 10, 'Page ' + str(self.page_no()), 0, 0, 'C')
14+
15+
16+
def save_pdf(medicines):
17+
pdf = PDF()
18+
19+
# Add a page
20+
pdf.add_page()
21+
22+
# setting style and size of font for the pdf
23+
pdf.set_font("Arial", size=12)
24+
pdf.cell(
25+
200, 10,
26+
txt="Generated Prscription",
27+
ln=1, align='C'
28+
)
29+
30+
for medic in medicines:
31+
if ('Medicine Name' in medicines[medic]):
32+
# create a cell
33+
pdf.cell(
34+
200, 10,
35+
ln=1, align='C',
36+
txt=medic
37+
)
38+
pdf.cell(
39+
200, 10,
40+
ln=2,
41+
txt="Medicine Name: " + medicines[medic]["Medicine Name"],
42+
)
43+
if "Instruction" in medicines[medic]:
44+
pdf.cell(
45+
200, 10,
46+
ln=2,
47+
txt="Instructions: " + medicines[medic]["Instruction"]
48+
)
49+
else:
50+
pdf.cell(
51+
200, 10,
52+
ln=2,
53+
txt="Instructions*: No Instructions given"
54+
)
55+
56+
# save the pdf with name .pdf
57+
pdf.output("Prescription.pdf")
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import speech_recognition as sr
2+
3+
4+
def speech_rec_for_linux():
5+
import espeak
6+
espeak.init()
7+
speaker = espeak.Espeak()
8+
# import pyttsx3
9+
# speaker = pyttsx3.init()
10+
11+
r = sr.Recognizer()
12+
text = ""
13+
count = 0
14+
medicines = {}
15+
16+
with sr.Microphone() as source:
17+
while(True):
18+
medicine_dict = {}
19+
count += 1
20+
21+
print("Medicine-" + str(count) + " Information")
22+
23+
print("Adjusting noise ")
24+
r.adjust_for_ambient_noise(source, duration=1)
25+
26+
print("Medicine Name:")
27+
speaker.say("Medicine name")
28+
# speaker.rate = 300
29+
30+
recorded_audio = r.listen(source, timeout=6)
31+
print("Done")
32+
33+
try:
34+
text = r.recognize_google(
35+
recorded_audio,
36+
language="en-US"
37+
)
38+
if 'exit' in str(text).lower():
39+
print("Thanks for using our service!")
40+
break
41+
42+
medicine_dict["Medicine Name"] = str(text)
43+
print("Decoded Text : {}".format(text))
44+
45+
except Exception as e:
46+
print(e)
47+
48+
print("Adjusting noise ")
49+
r.adjust_for_ambient_noise(source, duration=1)
50+
51+
print("Medicine Instruction:")
52+
speaker.say("Medicine Instruction")
53+
54+
recorded_audio = r.listen(source, timeout=6)
55+
print("Done")
56+
57+
try:
58+
text = r.recognize_google(
59+
recorded_audio,
60+
language="en-US"
61+
)
62+
medicine_dict["Instruction"] = str(text)
63+
print("Decoded Text : {}".format(text))
64+
65+
except Exception as e:
66+
print(e)
67+
68+
medicines["Medicine No. " + str(count)] = medicine_dict
69+
70+
return medicines
71+
72+
73+
def speech_rec_for_windows():
74+
import pyttsx3
75+
speaker = pyttsx3.init()
76+
# from win32com.client import Dispatch
77+
# speak = Dispatch("SAPI.SpVoice").Speak
78+
79+
r = sr.Recognizer()
80+
text = ""
81+
count = 0
82+
medicines = {}
83+
84+
with sr.Microphone() as source:
85+
while(True):
86+
medicine_dict = {}
87+
count += 1
88+
89+
print("Medicine-" + str(count) + " Information")
90+
91+
print("Adjusting noise ")
92+
r.adjust_for_ambient_noise(source, duration=1)
93+
94+
print("Medicine Name:")
95+
speaker.say("Medicine name")
96+
speaker.runAndWait()
97+
98+
recorded_audio = r.listen(source, timeout=6)
99+
print("Done")
100+
101+
try:
102+
text = r.recognize_google(
103+
recorded_audio,
104+
language="en-US"
105+
)
106+
if 'exit' in str(text).lower():
107+
print("Thanks for using our service!")
108+
break
109+
110+
medicine_dict["Medicine Name"] = str(text)
111+
print("Decoded Text : {}".format(text))
112+
113+
except Exception as e:
114+
print("Exception", e)
115+
116+
print("Adjusting noise ")
117+
r.adjust_for_ambient_noise(source, duration=1)
118+
119+
print("Medicine Instruction:")
120+
speaker.say("Medicine Instruction")
121+
speaker.runAndWait()
122+
123+
recorded_audio = r.listen(source, timeout=6)
124+
print("Done")
125+
126+
try:
127+
text = r.recognize_google(
128+
recorded_audio,
129+
language="en-US"
130+
)
131+
medicine_dict["Instruction"] = str(text)
132+
print("Decoded Text : {}".format(text))
133+
134+
except Exception as e:
135+
print("Exception", e)
136+
137+
medicines["Medicine No. " + str(count)] = medicine_dict
138+
139+
return medicines

prescription_generator/main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
from helper.pdf_operations import save_pdf
3+
from helper.speech import speech_rec_for_windows, speech_rec_for_linux
4+
5+
6+
def start_app():
7+
if sys.platform.startswith('linux'):
8+
medicines = speech_rec_for_linux()
9+
10+
elif sys.platform.startswith('win32'):
11+
medicines = speech_rec_for_windows()
12+
13+
print(medicines)
14+
save_pdf(medicines)
15+
16+
17+
if __name__ == '__main__':
18+
start_app()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
beautifulsoup4==4.9.3
2+
certifi==2020.12.5
3+
chardet==4.0.0
4+
docopt==0.6.2
5+
fpdf==1.7.2
6+
idna==2.10
7+
Js2Py==0.71
8+
packaging==20.9
9+
pipwin==0.5.1
10+
PyAudio==0.2.11
11+
pydub==0.25.1
12+
pyjsparser==2.7.1
13+
pyparsing==2.4.7
14+
PyPrind==2.11.2
15+
pySmartDL==1.3.4
16+
python-espeak==0.6.3
17+
pytz==2021.1
18+
requests==2.25.1
19+
six==1.15.0
20+
soupsieve==2.2.1
21+
SpeechRecognition==3.8.1
22+
tzlocal==2.1
23+
urllib3==1.26.4

0 commit comments

Comments
 (0)