0% found this document useful (0 votes)
2 views

NIX.py

The document outlines a Python script that utilizes various libraries for speech recognition and text-to-speech functionalities. It listens for voice commands, processes them, and responds with information or actions such as playing music, telling jokes, or providing the current time and date. The script runs in an infinite loop, continuously waiting for user commands prefixed with 'Nix'.

Uploaded by

『SEÑÅTØR』
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

NIX.py

The document outlines a Python script that utilizes various libraries for speech recognition and text-to-speech functionalities. It listens for voice commands, processes them, and responds with information or actions such as playing music, telling jokes, or providing the current time and date. The script runs in an infinite loop, continuously waiting for user commands prefixed with 'Nix'.

Uploaded by

『SEÑÅTØR』
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import speech_recognition as sr

import pyttsx3
import datetime
import pyjokes
import pywhatkit
import wikipedia
import os
import webbrowser
import subprocess

listener = sr.Recognizer()
engine4 = (pyttsx3.init())
voices = engine4.getProperty('voices')
engine4.setProperty('voice', voices[1].id)
import speech_recognition as sr

recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Listening !")
audio = recognizer.listen(source)
voice = listener.listen(source, timeout=1, phrase_time_limit=6)
listener.adjust_for_ambient_noise(source, duration=1)
print(f"Energy threshold: {listener.energy_threshold}")

try:
print("Query: " + recognizer.recognize_google(audio))
except sr.UnknownValueError:
print("Sorry, could not understand audio.")
except sr.RequestError:
print("Could not request results; check your internet connection.")
recognizer.energy_threshold = 300

def talk(text):
engine4.say(text)
engine4.runAndWait()
wiki = wikipedia.summary(text, sentences=2)
print(wiki)
talk(wiki)
def take_Command():
try:
with sr.Microphone() as source:
print("Listening...")
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'Nix' in command:
command = command.replace('Nix', '')
print(command)
except:
pass
return command
def run_nix():
command = take_Command()
if command:
print(f"Processing command: {command}")
if 'play' in command:
song = command.replace('play', '').strip()
talk('playing ' + song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('Current time is ' + time)
elif 'joke' in command:
joke = pyjokes.get_joke()
talk(joke)
elif 'who is' in command:
person = command.replace('who is', '').strip()
wiki_info = wikipedia.summary(person, sentences=2)
talk(wiki_info)
elif 'date' in command:
talk('The current date is ' +
datetime.datetime.now().strftime('%d/%m/%Y'))
elif 'are you single' in command:
talk('I am not interested in relationships.')
else:
talk('Pardon? Please say that again.')
else:
print("No command detected.")

while True:
run_nix()

You might also like