-
Notifications
You must be signed in to change notification settings - Fork 1
/
speech.py
37 lines (28 loc) · 1019 Bytes
/
speech.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
from selenium import webdriver
from time import sleep
import speech_recognition as sr
import pyaudio
from main import *
def recognizeVoice():
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
dev = p.get_device_info_by_index(i)
if (dev['name'] == 'Stereo Mix (Realtek(R) Audio)' and dev['hostApi'] == 0):
dev_index = dev['index']
print('dev_index', dev_index)
while(True):
r = sr.Recognizer()
print(1)
with sr.Microphone(device_index=dev_index) as source:
audio = r.listen(source)
print(2)
MyText = r.recognize_google(audio, language = 'en-IN', show_all = True)
print(3)
text = MyText.get('alternative')
a = text[0]
recognizedVoice = a['transcript']
print(recognizedVoice)
if 'chandan' in recognizedVoice:
markAttendence(message,chatbutton,textarea,sendbutton)
else:
pass