-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.py
71 lines (55 loc) · 1.89 KB
/
sample.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# import sounddevice as sd
# from scipy.io.wavfile import write
# import wavio as wv
# import numpy as np
from tkinter import messagebox
import speech_recognition as sr
# freq = 44100
# # def recording
# # for i in range(n):
# arr = np.empty(0)
# duration = 5
# for i in range (1 , duration+1):
# print(i)
# if (duration != -1):
# recording = sd.rec(int (i * freq) , samplerate = freq , channels = 2)
# arr = np.append(arr , recording)
# sd.wait()
# print(arr)
# write("recording4.wav" , freq , arr)
# wv.write("recording5.wav" , arr , freq , sampwidth = 2)
def record():
lang = ""
lan = input("Enter language to Recognize:")
languages = ['en-Us' , 'hi-IN']
if (lan == "English"):
lang = languages[0]
elif (lan == "Hindi"):
lang = languages[1]
else:
print("Language not Supported!")
if (lan == "English" or lan == "Hindi"):
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print('Clearing background noise..')
recognizer.adjust_for_ambient_noise(source,duration=1)
print("waiting for your message...")
recordedaudio=recognizer.listen(source)
print('Done recording..!')
print(recordedaudio)
try:
print('Printing the message..')
text=recognizer.recognize_google(recordedaudio,language = lang)
print('Your message:{}'.format(text))
# messagebox.showinfo(title = "Message" , message = text)
return text
except Exception as ex:
print(ex)
if __name__ == '__main__':
i = 1
while (i != 0):
# i = int(input("Enter the value: "))
if (i != 0):
a = record()
print(a)
# messagebox.showinfo(title = "Message" , message = a)