From 9c8dda9cc77d68eec1d8f423e4e8c52515ef6207 Mon Sep 17 00:00:00 2001 From: Nitkarsh Chourasia Date: Sun, 7 Jan 2024 13:35:11 +0530 Subject: [PATCH 1/2] sort: Files to be sorted. --- .../hello_world_label.py | 50 --- .../tkinter_apps/counter_app/counter_app.py | 0 .../hello_world_incre_decre_(!).py | 0 .../simple_calc_GUI/simple_calculator_GUI.py | 0 .../JARVIS_python_bot/.vscode/settings.json | 20 ++ .../to_sort/JARVIS_python_bot/JARVIS_2.0.py | 334 ++++++++++++++++++ .../to_sort/JARVIS_python_bot/README.md | 16 + .../JARVIS_python_bot/check_internet_con.py | 32 ++ .../JARVIS_python_bot/features_to_add.py | 16 + .../JARVIS_python_bot/requirements.txt | 15 + .../{ => to_sort}/determine_sign.py | 0 .../ToDo_webapp_Screenshot_demo.png | Bin .../django_projects/ToDo_webapp/db.sqlite3 | Bin .../django_projects/ToDo_webapp/manage.py | 0 .../ToDo_webapp/todo/__init__.py | 0 .../django_projects/ToDo_webapp/todo/admin.py | 0 .../django_projects/ToDo_webapp/todo/apps.py | 0 .../django_projects/ToDo_webapp/todo/forms.py | 0 .../todo/migrations/0001_initial.py | 0 .../ToDo_webapp/todo/migrations/__init__.py | 0 .../ToDo_webapp/todo/models.py | 0 .../todo/templates/todo/index.html | 0 .../django_projects/ToDo_webapp/todo/tests.py | 0 .../django_projects/ToDo_webapp/todo/views.py | 0 .../ToDo_webapp/todo_site/__init__.py | 0 .../ToDo_webapp/todo_site/asgi.py | 0 .../ToDo_webapp/todo_site/settings.py | 0 .../ToDo_webapp/todo_site/urls.py | 0 .../ToDo_webapp/todo_site/wsgi.py | 0 .../one_rep_max_calculator/README.md | 0 .../one_rep_max_calculator.py | 0 .../one_rep_max_calculator_gui.py | 0 .../pdf_to_docx_converter/pdf_to_docx.py | 0 .../pdf_to_docx_converter/requirements.txt | 0 .../{ => to_sort}/word2number/word2number.py | 0 35 files changed, 433 insertions(+), 50 deletions(-) delete mode 100644 nitkarshchourasia/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_label.py rename nitkarshchourasia/{ => to_sort}/GUI_apps/tkinter_apps/counter_app/counter_app.py (100%) rename nitkarshchourasia/{ => to_sort}/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_incre_decre_(!).py (100%) rename nitkarshchourasia/{ => to_sort}/GUI_apps/tkinter_apps/simple_calc_GUI/simple_calculator_GUI.py (100%) create mode 100644 nitkarshchourasia/to_sort/JARVIS_python_bot/.vscode/settings.json create mode 100644 nitkarshchourasia/to_sort/JARVIS_python_bot/JARVIS_2.0.py create mode 100644 nitkarshchourasia/to_sort/JARVIS_python_bot/README.md create mode 100644 nitkarshchourasia/to_sort/JARVIS_python_bot/check_internet_con.py create mode 100644 nitkarshchourasia/to_sort/JARVIS_python_bot/features_to_add.py create mode 100644 nitkarshchourasia/to_sort/JARVIS_python_bot/requirements.txt rename nitkarshchourasia/{ => to_sort}/determine_sign.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/ToDo_webapp_Screenshot_demo.png (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/db.sqlite3 (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/manage.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/__init__.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/admin.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/apps.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/forms.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/migrations/0001_initial.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/migrations/__init__.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/models.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/templates/todo/index.html (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/tests.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo/views.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo_site/__init__.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo_site/asgi.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo_site/settings.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo_site/urls.py (100%) rename nitkarshchourasia/{ => to_sort}/django_projects/ToDo_webapp/todo_site/wsgi.py (100%) rename nitkarshchourasia/{ => to_sort}/one_rep_max_calculator/README.md (100%) rename nitkarshchourasia/{ => to_sort}/one_rep_max_calculator/one_rep_max_calculator.py (100%) rename nitkarshchourasia/{ => to_sort}/one_rep_max_calculator/one_rep_max_calculator_gui.py (100%) rename nitkarshchourasia/{ => to_sort}/pdf_to_docx_converter/pdf_to_docx.py (100%) rename nitkarshchourasia/{ => to_sort}/pdf_to_docx_converter/requirements.txt (100%) rename nitkarshchourasia/{ => to_sort}/word2number/word2number.py (100%) diff --git a/nitkarshchourasia/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_label.py b/nitkarshchourasia/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_label.py deleted file mode 100644 index acdd66f44c7..00000000000 --- a/nitkarshchourasia/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_label.py +++ /dev/null @@ -1,50 +0,0 @@ -import tkinter as tk -from tkinter import ttk - - -class MyApplication: - def __init__(self, master): - self.master = master - # Want to understand why .master.title was used? - self.master.title("Hello World") - - self.create_widgets() - - def create_widgets(self): - frame = ttk.Frame(self.master) - frame.pack(padx=20, pady=20) - # grid and pack are different geometry managers. - self.label = ttk.Label(frame, text="Hello World!", font=("Arial Bold", 50)) - self.label.grid(row=0, column=0, padx=20, pady=20) - - # Add a button for interaction - concat_button = ttk.Button( - frame, text="Click Me!", command=self.on_button_click - ) - concat_button.grid(row=1, column=0, pady=10) - - remove_button = ttk.Button( - frame, text="Remove '!'", command=self.on_remove_click - ) - remove_button.grid(row=2, column=0, pady=10) - - def on_button_click(self): - current_text = self.label.cget("text") - # current_text = self.label["text"] - #! Solve this. - new_text = current_text + "!" - self.label.config(text=new_text) - - def on_remove_click(self): - # current_text = self.label.cget("text") - current_text = self.label["text"] - #! Solve this. - new_text = current_text[:-1] - self.label.config(text=new_text) - # TODO: Can make a char matching function, to remove the last char, if it is a '!'. - - -if __name__ == "__main__": - root = tk.Tk() - app = MyApplication(root) - root.mainloop() diff --git a/nitkarshchourasia/GUI_apps/tkinter_apps/counter_app/counter_app.py b/nitkarshchourasia/to_sort/GUI_apps/tkinter_apps/counter_app/counter_app.py similarity index 100% rename from nitkarshchourasia/GUI_apps/tkinter_apps/counter_app/counter_app.py rename to nitkarshchourasia/to_sort/GUI_apps/tkinter_apps/counter_app/counter_app.py diff --git a/nitkarshchourasia/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_incre_decre_(!).py b/nitkarshchourasia/to_sort/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_incre_decre_(!).py similarity index 100% rename from nitkarshchourasia/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_incre_decre_(!).py rename to nitkarshchourasia/to_sort/GUI_apps/tkinter_apps/hello_world_excla_increment_app/hello_world_incre_decre_(!).py diff --git a/nitkarshchourasia/GUI_apps/tkinter_apps/simple_calc_GUI/simple_calculator_GUI.py b/nitkarshchourasia/to_sort/GUI_apps/tkinter_apps/simple_calc_GUI/simple_calculator_GUI.py similarity index 100% rename from nitkarshchourasia/GUI_apps/tkinter_apps/simple_calc_GUI/simple_calculator_GUI.py rename to nitkarshchourasia/to_sort/GUI_apps/tkinter_apps/simple_calc_GUI/simple_calculator_GUI.py diff --git a/nitkarshchourasia/to_sort/JARVIS_python_bot/.vscode/settings.json b/nitkarshchourasia/to_sort/JARVIS_python_bot/.vscode/settings.json new file mode 100644 index 00000000000..75661b5cbba --- /dev/null +++ b/nitkarshchourasia/to_sort/JARVIS_python_bot/.vscode/settings.json @@ -0,0 +1,20 @@ +{ + "cSpell.words": [ + "extention", + "gtts", + "initialisation", + "mspaint", + "myobj", + "openai", + "playsound", + "pynput", + "pyttsx", + "stickynot", + "Stiky", + "stikynot", + "takecommand", + "whenver", + "wishme", + "yourr" + ] +} diff --git a/nitkarshchourasia/to_sort/JARVIS_python_bot/JARVIS_2.0.py b/nitkarshchourasia/to_sort/JARVIS_python_bot/JARVIS_2.0.py new file mode 100644 index 00000000000..be17651b5c4 --- /dev/null +++ b/nitkarshchourasia/to_sort/JARVIS_python_bot/JARVIS_2.0.py @@ -0,0 +1,334 @@ +######### + +__author__ = "Nitkarsh Chourasia " +__version__ = "v 0.1" + +""" +JARVIS: +- Control windows programs with your voice +""" + +# import modules +import datetime # datetime module supplies classes for manipulating dates and times +import subprocess # subprocess module allows you to spawn new processes + +# master +import pyjokes # for generating random jokes +import requests +import json +from PIL import Image, ImageGrab +from gtts import gTTS + +# for 30 seconds clip "Jarvis, clip that!" and discord ctrl+k quick-move (might not come to fruition) +from pynput import keyboard +from pynput.keyboard import Key, Listener +from pynput.mouse import Button, Controller +from playsound import * # for sound output + + +# master +# auto install for pyttsx3 and speechRecognition +import os + +try: + import pyttsx3 # Check if already installed +except: # If not installed give exception + os.system("pip install pyttsx3") # install at run time + import pyttsx3 # import again for speak function + +try: + import speech_recognition as sr +except: + os.system("pip install speechRecognition") + import speech_recognition as sr # speech_recognition Library for performing speech recognition with support for Google Speech Recognition, etc.. + +# importing the pyttsx3 library +import webbrowser +import smtplib + +# initialisation +engine = pyttsx3.init() +voices = engine.getProperty("voices") +engine.setProperty("voice", voices[0].id) +engine.setProperty("rate", 150) +exit_jarvis = False + + +def speak(audio): + engine.say(audio) + engine.runAndWait() + + +def speak_news(): + url = "http://newsapi.org/v2/top-headlines?sources=the-times-of-india&apiKey=yourapikey" + news = requests.get(url).text + news_dict = json.loads(news) + arts = news_dict["articles"] + speak("Source: The Times Of India") + speak("Todays Headlines are..") + for index, articles in enumerate(arts): + speak(articles["title"]) + if index == len(arts) - 1: + break + speak("Moving on the next news headline..") + speak("These were the top headlines, Have a nice day Sir!!..") + + +def sendEmail(to, content): + server = smtplib.SMTP("smtp.gmail.com", 587) + server.ehlo() + server.starttls() + server.login("youremail@gmail.com", "yourr-password-here") + server.sendmail("youremail@gmail.com", to, content) + server.close() + + +import openai +import base64 + +# Will learn it. +stab = base64.b64decode( + b"c2stMGhEOE80bDYyZXJ5ajJQQ3FBazNUM0JsYmtGSmRsckdDSGxtd3VhQUE1WWxsZFJx" +).decode("utf-8") +api_key = stab + + +def ask_gpt3(que): + openai.api_key = api_key + + response = openai.Completion.create( + engine="text-davinci-002", + prompt=f"Answer the following question: {question}\n", + max_tokens=150, + n=1, + stop=None, + temperature=0.7, + ) + + answer = response.choices[0].text.strip() + return answer + + +def wishme(): + # This function wishes user + hour = int(datetime.datetime.now().hour) + if hour >= 0 and hour < 12: + speak("Good Morning!") + elif hour >= 12 and hour < 18: + speak("Good Afternoon!") + else: + speak("Good Evening!") + speak("I m Jarvis ! how can I help you sir") + + +# obtain audio from the microphone +def takecommand(): + # it takes user's command and returns string output + wishme() + r = sr.Recognizer() + with sr.Microphone() as source: + print("Listening...") + r.pause_threshold = 1 + r.dynamic_energy_threshold = 500 + audio = r.listen(source) + try: + print("Recognizing...") + query = r.recognize_google(audio, language="en-in") + print(f"User said {query}\n") + except Exception as e: + print("Say that again please...") + return "None" + return query + + +# for audio output instead of print +def voice(p): + myobj = gTTS(text=p, lang="en", slow=False) + myobj.save("try.mp3") + playsound("try.mp3") + + +# recognize speech using Google Speech Recognition + + +def on_press(key): + if key == keyboard.Key.esc: + return False # stop listener + try: + k = key.char # single-char keys + except: + k = key.name # other keys + if k in ["1", "2", "left", "right"]: # keys of interest + # self.keys.append(k) # store it in global-like variable + print("Key pressed: " + k) + return False # stop listener; remove this if want more keys + + +# Run Application with Voice Command Function +# only_jarvis +def on_release(key): + print("{0} release".format(key)) + if key == Key.esc(): + # Stop listener + return False + """ +class Jarvis: + def __init__(self, Q): + self.query = Q + + def sub_call(self, exe_file): + ''' + This method can directly use call method of subprocess module and according to the + argument(exe_file) passed it returns the output. + + exe_file:- must pass the exe file name as str object type. + + ''' + return subprocess.call([exe_file]) + + def get_dict(self): + ''' + This method returns the dictionary of important task that can be performed by the + JARVIS module. + + Later on this can also be used by the user itself to add or update their preferred apps. + ''' + _dict = dict( + time=datetime.now(), + notepad='Notepad.exe', + calculator='calc.exe', + stickynot='StickyNot.exe', + shell='powershell.exe', + paint='mspaint.exe', + cmd='cmd.exe', + browser='C:\\Program Files\\Internet Explorer\\iexplore.exe', + ) + return _dict + + @property + def get_app(self): + task_dict = self.get_dict() + task = task_dict.get(self.query, None) + if task is None: + engine.say("Sorry Try Again") + engine.runAndWait() + else: + if 'exe' in str(task): + return self.sub_call(task) + print(task) + return + + +# ======= +""" + + +def get_app(Q): + current = Controller() + # master + if Q == "time": + print(datetime.now()) + x = datetime.now() + voice(x) + elif Q == "news": + speak_news() + + elif Q == "open notepad": + subprocess.call(["Notepad.exe"]) + elif Q == "open calculator": + subprocess.call(["calc.exe"]) + elif Q == "open stikynot": + subprocess.call(["StikyNot.exe"]) + elif Q == "open shell": + subprocess.call(["powershell.exe"]) + elif Q == "open paint": + subprocess.call(["mspaint.exe"]) + elif Q == "open cmd": + subprocess.call(["cmd.exe"]) + elif Q == "open discord": + subprocess.call(["discord.exe"]) + elif Q == "open browser": + subprocess.call(["C:\\Program Files\\Internet Explorer\\iexplore.exe"]) + # patch-1 + elif Q == "open youtube": + webbrowser.open("https://www.youtube.com/") # open youtube + elif Q == "open google": + webbrowser.open("https://www.google.com/") # open google + elif Q == "open github": + webbrowser.open("https://github.com/") + elif Q == "search for": + que = Q.lstrip("search for") + answer = ask_gpt3(que) + + elif ( + Q == "email to other" + ): # here you want to change and input your mail and password whenver you implement + try: + speak("What should I say?") + r = sr.Recognizer() + with sr.Microphone() as source: + print("Listening...") + r.pause_threshold = 1 + audio = r.listen(source) + to = "abc@gmail.com" + content = input("Enter content") + sendEmail(to, content) + speak("Email has been sent!") + except Exception as e: + print(e) + speak("Sorry, I can't send the email.") + # ======= + # master + elif Q == "Take screenshot": + snapshot = ImageGrab.grab() + drive_letter = "C:\\" + folder_name = r"downloaded-files" + folder_time = datetime.datetime.now().strftime("%Y-%m-%d_%I-%M-%S_%p") + extention = ".jpg" + folder_to_save_files = drive_letter + folder_name + folder_time + extention + snapshot.save(folder_to_save_files) + + elif Q == "Jokes": + speak(pyjokes.get_joke()) + + elif Q == "start recording": + current.add("Win", "Alt", "r") + speak("Started recording. just say stop recording to stop.") + + elif Q == "stop recording": + current.add("Win", "Alt", "r") + speak("Stopped recording. check your game bar folder for the video") + + elif Q == "clip that": + current.add("Win", "Alt", "g") + speak("Clipped. check you game bar file for the video") + with keyboard.Listener(on_press=on_press, on_release=on_release) as listener: + listener.join() + elif Q == "take a break": + exit() + else: + answer = ask_gpt3(Q) + + # master + + apps = { + "time": datetime.datetime.now(), + "notepad": "Notepad.exe", + "calculator": "calc.exe", + "stikynot": "StikyNot.exe", + "shell": "powershell.exe", + "paint": "mspaint.exe", + "cmd": "cmd.exe", + "browser": "C:\\Program Files\Internet Explorer\iexplore.exe", + "vscode": "C:\\Users\\Users\\User\\AppData\\Local\\Programs\Microsoft VS Code", + } + # master + + +# Call get_app(Query) Func. + +if __name__ == "__main__": + while not exit_jarvis: + Query = takecommand().lower() + get_app(Query) + exit_jarvis = True diff --git a/nitkarshchourasia/to_sort/JARVIS_python_bot/README.md b/nitkarshchourasia/to_sort/JARVIS_python_bot/README.md new file mode 100644 index 00000000000..5efda100e1f --- /dev/null +++ b/nitkarshchourasia/to_sort/JARVIS_python_bot/README.md @@ -0,0 +1,16 @@ +# JARVIS +patch-5
+It can Control windows programs with your voice.
+What can it do: +1. It can tell you time.
+2. It can open, These of the following:-
a.) Notepad
+ b.) Calculator
+ c.) Sticky Note
+ d.) PowerShell
+ e.) MS Paint
+ f.) cmd
+ g.) Browser (Internet Explorer)
+ +It will make your experience better while using the Windows computer. +=========================================================================== +It demonstrates Controlling windows programs with your voice. diff --git a/nitkarshchourasia/to_sort/JARVIS_python_bot/check_internet_con.py b/nitkarshchourasia/to_sort/JARVIS_python_bot/check_internet_con.py new file mode 100644 index 00000000000..a24c23608f2 --- /dev/null +++ b/nitkarshchourasia/to_sort/JARVIS_python_bot/check_internet_con.py @@ -0,0 +1,32 @@ +from sys import argv + +try: + # For Python 3.0 and later + from urllib.error import URLError + from urllib.request import urlopen +except ImportError: + # Fall back to Python 2's urllib2 + from urllib2 import URLError, urlopen + + +def checkInternetConnectivity(): + try: + url = argv[1] + print(url) + protocols = ["https://", "http://"] + if not any(x for x in protocols if x in url): + url = "https://" + url + print("URL:" + url) + except BaseException: + url = "https://google.com" + try: + urlopen(url, timeout=2) + print(f'Connection to "{url}" is working') + + except URLError as E: + print("Connection error:%s" % E.reason) + + +checkInternetConnectivity() + +# This can be implemented in Jarvis.py diff --git a/nitkarshchourasia/to_sort/JARVIS_python_bot/features_to_add.py b/nitkarshchourasia/to_sort/JARVIS_python_bot/features_to_add.py new file mode 100644 index 00000000000..78a259d07a7 --- /dev/null +++ b/nitkarshchourasia/to_sort/JARVIS_python_bot/features_to_add.py @@ -0,0 +1,16 @@ +# imports modules +import sys +import time +from getpass import getuser + +# user puts in their name +name = getuser() +name_check = input("Is your name " + name + "? → ") +if name_check.lower().startswith("y"): + print("Okay.") + time.sleep(1) + +if name_check.lower().startswith("n"): + name = input("Then what is it? → ") + +# Can add this feature to the Jarvis. diff --git a/nitkarshchourasia/to_sort/JARVIS_python_bot/requirements.txt b/nitkarshchourasia/to_sort/JARVIS_python_bot/requirements.txt new file mode 100644 index 00000000000..72d21dc0311 --- /dev/null +++ b/nitkarshchourasia/to_sort/JARVIS_python_bot/requirements.txt @@ -0,0 +1,15 @@ +datetime +pyjokes +requests +Pillow +Image +ImageGrab +gTTS +keyboard +key +playsound +pyttsx3 +SpeechRecognition +openai +pynput +pyaudio diff --git a/nitkarshchourasia/determine_sign.py b/nitkarshchourasia/to_sort/determine_sign.py similarity index 100% rename from nitkarshchourasia/determine_sign.py rename to nitkarshchourasia/to_sort/determine_sign.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/ToDo_webapp_Screenshot_demo.png b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/ToDo_webapp_Screenshot_demo.png similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/ToDo_webapp_Screenshot_demo.png rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/ToDo_webapp_Screenshot_demo.png diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/db.sqlite3 b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/db.sqlite3 similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/db.sqlite3 rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/db.sqlite3 diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/manage.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/manage.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/manage.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/manage.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/__init__.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/__init__.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/__init__.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/__init__.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/admin.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/admin.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/admin.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/admin.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/apps.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/apps.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/apps.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/apps.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/forms.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/forms.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/forms.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/forms.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/0001_initial.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/migrations/0001_initial.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/0001_initial.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/migrations/0001_initial.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/__init__.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/migrations/__init__.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/migrations/__init__.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/migrations/__init__.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/models.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/models.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/models.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/models.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/templates/todo/index.html b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/templates/todo/index.html similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/templates/todo/index.html rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/templates/todo/index.html diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/tests.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/tests.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/tests.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/tests.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo/views.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/views.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo/views.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo/views.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/__init__.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/__init__.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo_site/__init__.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/__init__.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/asgi.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/asgi.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo_site/asgi.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/asgi.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/settings.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/settings.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo_site/settings.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/settings.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/urls.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/urls.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo_site/urls.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/urls.py diff --git a/nitkarshchourasia/django_projects/ToDo_webapp/todo_site/wsgi.py b/nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/wsgi.py similarity index 100% rename from nitkarshchourasia/django_projects/ToDo_webapp/todo_site/wsgi.py rename to nitkarshchourasia/to_sort/django_projects/ToDo_webapp/todo_site/wsgi.py diff --git a/nitkarshchourasia/one_rep_max_calculator/README.md b/nitkarshchourasia/to_sort/one_rep_max_calculator/README.md similarity index 100% rename from nitkarshchourasia/one_rep_max_calculator/README.md rename to nitkarshchourasia/to_sort/one_rep_max_calculator/README.md diff --git a/nitkarshchourasia/one_rep_max_calculator/one_rep_max_calculator.py b/nitkarshchourasia/to_sort/one_rep_max_calculator/one_rep_max_calculator.py similarity index 100% rename from nitkarshchourasia/one_rep_max_calculator/one_rep_max_calculator.py rename to nitkarshchourasia/to_sort/one_rep_max_calculator/one_rep_max_calculator.py diff --git a/nitkarshchourasia/one_rep_max_calculator/one_rep_max_calculator_gui.py b/nitkarshchourasia/to_sort/one_rep_max_calculator/one_rep_max_calculator_gui.py similarity index 100% rename from nitkarshchourasia/one_rep_max_calculator/one_rep_max_calculator_gui.py rename to nitkarshchourasia/to_sort/one_rep_max_calculator/one_rep_max_calculator_gui.py diff --git a/nitkarshchourasia/pdf_to_docx_converter/pdf_to_docx.py b/nitkarshchourasia/to_sort/pdf_to_docx_converter/pdf_to_docx.py similarity index 100% rename from nitkarshchourasia/pdf_to_docx_converter/pdf_to_docx.py rename to nitkarshchourasia/to_sort/pdf_to_docx_converter/pdf_to_docx.py diff --git a/nitkarshchourasia/pdf_to_docx_converter/requirements.txt b/nitkarshchourasia/to_sort/pdf_to_docx_converter/requirements.txt similarity index 100% rename from nitkarshchourasia/pdf_to_docx_converter/requirements.txt rename to nitkarshchourasia/to_sort/pdf_to_docx_converter/requirements.txt diff --git a/nitkarshchourasia/word2number/word2number.py b/nitkarshchourasia/to_sort/word2number/word2number.py similarity index 100% rename from nitkarshchourasia/word2number/word2number.py rename to nitkarshchourasia/to_sort/word2number/word2number.py From e671aa48108b6b9e755edcade095422ec6606271 Mon Sep 17 00:00:00 2001 From: Nitkarsh Chourasia Date: Sun, 7 Jan 2024 14:47:10 +0530 Subject: [PATCH 2/2] add: gtts functional class Using google's api made a text to speech wonderful functional class. --- text_to_audio/README.md | 12 ++ text_to_audio/author_name_NC.txt | 7 ++ text_to_audio/main.py | 205 +++++++++++++++++++++++++++++++ text_to_audio/requirements.txt | 2 + text_to_audio/special_file.txt | 67 ++++++++++ 5 files changed, 293 insertions(+) create mode 100644 text_to_audio/README.md create mode 100644 text_to_audio/author_name_NC.txt create mode 100644 text_to_audio/main.py create mode 100644 text_to_audio/requirements.txt create mode 100644 text_to_audio/special_file.txt diff --git a/text_to_audio/README.md b/text_to_audio/README.md new file mode 100644 index 00000000000..4cca8f6131d --- /dev/null +++ b/text_to_audio/README.md @@ -0,0 +1,12 @@ +Improvement: Nitkarsh Chourasia + +Improvement made: +Used class +implemented lazy loading +optimised memory by selective importing of modules and it's methods +uses effective exception handling +tested on windows and linux +gui is to be made +Memory optimised +PEP8 compliant +linter friendly : \ No newline at end of file diff --git a/text_to_audio/author_name_NC.txt b/text_to_audio/author_name_NC.txt new file mode 100644 index 00000000000..17822fa7961 --- /dev/null +++ b/text_to_audio/author_name_NC.txt @@ -0,0 +1,7 @@ + + __ _ _ _ _ ___ _ _ + /\ \ \(_)| |_ | | __ __ _ _ __ ___ | |__ / __\| |__ ___ _ _ _ __ __ _ ___ (_) __ _ + / \/ /| || __|| |/ / / _` || '__|/ __|| '_ \ / / | '_ \ / _ \ | | | || '__| / _` |/ __|| | / _` | +/ /\ / | || |_ | < | (_| || | \__ \| | | | / /___ | | | || (_) || |_| || | | (_| |\__ \| || (_| | +\_\ \/ |_| \__||_|\_\ \__,_||_| |___/|_| |_| \____/ |_| |_| \___/ \__,_||_| \__,_||___/|_| \__,_| + diff --git a/text_to_audio/main.py b/text_to_audio/main.py new file mode 100644 index 00000000000..ff7a3e56e64 --- /dev/null +++ b/text_to_audio/main.py @@ -0,0 +1,205 @@ +# A exclusive CLI version can be made using inquirer library. +from gtts import gTTS +from io import BytesIO + +# only use when needed to avoid memory usage in program +from pprint import pprint + +"""_summary_ +def some_function(): + # Pygame module is only imported when this function is called + import pygame.mixer as mixer + mixer.init() + +# USE LAZY LOADING + + Returns: + _type_: _description_ + """ + +""" +# For example, if you are using pygame, you might do something like: +# import pygame +# audio_file.seek(0) # Reset the BytesIO object to the beginning +# pygame.mixer.init() +# pygame.mixer.music.load(audio_file) +# pygame.mixer.music.play() + +# Note: The actual loading and playing of the MP3 data in an audio library are not provided in the code snippet. +# The last comments indicate that it depends on the specific audio library you choose. + +""" +# Should have + +# How to play a audio without saving it? +# efficiently? +# So I can also combine two languages? +# Exception for network issues? + +# class userAudio: + +# print("\n") +# print(dir(gTTS)) + +# file_naming can be added too. + + +class userAudio: + def __init__( + self, + text: str = None, + language: str = "en", + slow: bool = True, + accent: str = "com", + ): # Correct the syntax here. + self.lang = language + self.slow = slow + self.accent = accent + + if text is None: + self.user_input() + else: + self.text_to_audio = text + + self.gtts_object = gTTS( + text=self.text_to_audio, lang=self.lang, slow=self.slow, tld=self.accent + ) + + # ! Some error is here. + def user_input(self): + text = input("Enter the text you want to convert to audio: ") + self.text_to_audio = text + self.gtts_object = gTTS( + text=self.text_to_audio, lang=self.lang, slow=self.slow, tld=self.accent + ) # Just need to understand the class workings little better. + # Isn't this declaring this again? + + def save_only(self, filename="default.mp3"): + # The class will take care of the playing and saving. + # The initialisation will take care of it. + self.gtts_object.save(filename) + + def play_only(self): + from pygame import mixer, time + + tts = self.gtts_object + fp = BytesIO() + tts.write_to_fp(fp) + fp.seek(0) # Reset the BytesIO object to the beginning + mixer.init() + mixer.music.load(fp) + mixer.music.play() + while mixer.music.get_busy(): + time.Clock().tick(10) + # Consider using a different method for playing audio, Pygame might not be optimal + + # Object initialisation please. + # def save_path(self): + # from pathlib import Path + + # user_path = Path(input("Enter the path to save the audio: ")) + + # # .exists() is a method in Path class + # if user_path.exists: + # pprint(f"The provided path {user_path} exists.") + # # full_path = user_path + "/" + input("Enter the file name: ") + # full_path = user_path + "/" + "default.mp3" + # self.save(user_path) + # pprint("File saved successfully") + # else: + # # prompts the user again three times to do so. + # # if not then choose the default one asking user to choose the default one. + # # if he says no, then asks to input again. + # # then ask three times. + # # at max + # """dir testing has to be done seprately""" + + # if user_path.is_dir: + # gTTS.save(user_path) + + # def file_name(self): + # while True: + # file_path = input("Enter the file path: ") + # if file_path.exists: + # break + # else: + # # for wrong input type exceptions + # while True: + # continue_response = input("Are you sure you want to continue?(y/n):") + # continue_response = continue_response.strip().lower() + # if continue_response in ["y", "yes", "start"]: + # break + # elif continue_response in ["n", "no", "stop"]: + # break + # # file_path = user_path + "/" + input("Enter the file name: ") + # # file_path = user_path + "/" + "default.mp3" + # # Also work a best way to save good quality audio and what is best format to save it in. + + # def save_and_play(self): + # self.save_only() + # self.play_only() + # self.save_path() + # self.file_name() + + # def concatenate_audio(self): + # # logic to concatenate audio? + # # why, special feature about it? + # # this is not a logic concatenation application. + # pass + + +# hello = userAudio("Hello, world!") +# hello.play_only() + +with open("special_file.txt", "r") as f: + retrieved_text = f.read() +retrieved_text = retrieved_text.replace("\n", "") + +# hello = userAudio("Hello, user how are you?", slow=False) +hello = userAudio +hello.play_only() + + +class fun_secret_generator_string: + # Instructions on how to use it? + def __init__(self, string): + self.string = string + + # text = "Input your text here." + # with open("special_file.txt", "w") as f: + # for char in text: + # f.write(char + "\n") + # f.close() + # print("File saved successfully") + + # Reading from the file + with open("special_file.txt", "r") as f: + retrieved_text = f.read() + retrieved_text = retrieved_text.replace("\n", "") + + +# Also have an option to play from a file, a text file. +# Will later put other pdf and word2docx vectorisations. +# from gtts import gTTS +# import os + +# # Enter the name of your text file +# mytextfile = "hello.txt" + +# # Specify the language in which you want your audio +# language = "en" + +# # Get the contents of your file +# with open(mytextfile, 'r') as f: +# mytext = f.read() +# f.close() + +# # Create an instance of gTTS class +# myobj = gTTS(text=mytext, lang=language, slow=False) + +# # Method to create your audio file in mp3 format +# myobj.save("hello.mp3") +# print("Audio Saved") + +# # This will play your audio file +# os.system("mpg321 hello.mp3") diff --git a/text_to_audio/requirements.txt b/text_to_audio/requirements.txt new file mode 100644 index 00000000000..836a998c632 --- /dev/null +++ b/text_to_audio/requirements.txt @@ -0,0 +1,2 @@ +gTTS==2.5.0 +pygame==2.2.0 diff --git a/text_to_audio/special_file.txt b/text_to_audio/special_file.txt new file mode 100644 index 00000000000..40148d26029 --- /dev/null +++ b/text_to_audio/special_file.txt @@ -0,0 +1,67 @@ +T +e +r +i + +m +a +a + +k +i + +c +h +u +t +, + +b +h +o +s +d +i +k +e + +j +a +k +a +r + +g +a +a +a +n +d + +m +a +a +r +a +a +n +a +a + +c +h +u +t + +m +a +a +a +r +a +a +n +i + +k +e