-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
47 lines (40 loc) · 1.15 KB
/
utils.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
import speech_recognition as sr
import pyttsx as pys
import engineio
import datetime
import wikipedia
import os
import webbrowser
import playsound
from gtts import gTTS
engineio = pys.init()
engineio.setProperty('rate', 150)
voices = engineio.getProperty('voices')
engineio.setProperty('voice',voices[1].id)
volume = engineio.getProperty('volume')
engineio.setProperty('volume',1.0)
def speak(audio):
engineio.say(audio)
engineio.runAndWait()
def saveVoice(audio):
tts = gTTS(text= audio)
filename = "voice.mp3"
tts.save(filename)
playsound.playsound(filename)
def Command():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
try:
instruction = r.recognize_google(audio)
print(instruction)
except sr.UnknownValueError:
print("Error")
speak("Oopss..There was some error please try again!")
# return None
except sr.RequestError as e:
print(e)
speak("Oopss..There was some error please try again!")
# return None
return instruction.lower()
# saveVoice("Hi I am fine")