Last active
January 16, 2022 14:51
-
-
Save avseng/bdc9e29a442911f9e43297a7d588db5d to your computer and use it in GitHub Desktop.
AI Voice Assistance using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install bellow libraries before running the VoiceAssistance.py | |
pip install speechrecognition | |
pip install gTTS | |
pip install wheel | |
pip install pipwin | |
pipwin install pyaudio | |
python3 -m pip install pyobj | |
pip install weathercom | |
pip install playsound |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import speech_recognition as sr | |
from gtts import gTTS | |
import playsound | |
import os | |
import weathercom | |
import json | |
r = sr.Recognizer() | |
def voice_command_processor(ask=False): | |
with sr.Microphone() as source: | |
if(ask): | |
audio_playback(ask) | |
audio = r.listen(source,phrase_time_limit=4) | |
text = '' | |
try: | |
text=r.recognize_google(audio) | |
except sr.UnknownValueError as e: | |
print(e) | |
except sr.RequestError as e: | |
print("service is down") | |
return text.lower() | |
def audio_playback(text): | |
filename = "test.mp3" | |
tts = gTTS(text=text, lang='en-us') | |
tts.save(filename) | |
playsound.playsound(filename) | |
os.remove(filename) | |
def execute_voice_command(text): | |
if "what are you" in text: | |
audio_playback("i am a i voice assistance system") | |
if "what is the today's weather" in text: | |
city = voice_command_processor("which city") | |
humidity, temp, phrase = weatherReport(city) | |
audio_playback("currently in " + city + " temperature is " + str(temp) | |
+ " degree celsius, " + "humidity is " + str(humidity) + " percent and sky is " + phrase) | |
print("currently in " + city + " temperature is " + str(temp) | |
+ "degree celsius, " + "humidity is " + str(humidity) + " percent and sky is " + phrase) | |
def weatherReport(city): | |
weatherDetails = weathercom.getCityWeatherDetails(city) | |
humidity = json.loads(weatherDetails)["vt1observation"]["humidity"] | |
temp = json.loads(weatherDetails)["vt1observation"]["temperature"] | |
phrase = json.loads(weatherDetails)["vt1observation"]["phrase"] | |
return humidity, temp, phrase | |
while True: | |
command = voice_command_processor() | |
print(command) | |
execute_voice_command(command) |
Bro!! am face this Error "NameError: name 'text' is not defined" ..... plz help
You know you'd have better SR (Speech Recognition) doing something like 'pip install nemo_toolkit[all]' and quartznet = nemo_asr.models.ASRModel.from_pretrained(model_name="QuartzNet15x5Base-En")
just to use a simple example instead of getting further in-depth. Also, I'm on Discord if you need help with something :) unicorns#7402
So please do let me know if something errors out here, ^ inferencing the model shouldn't be bad on a CPU, it's about 5-20 seconds on a CPU using my machine.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI, Sir I Copy & Paste Your Program on My Terminal .But It Shows a Error In this program. i don't know how to solve it .please, verify it