I have written a Python code that works well, but in the middle of using the code, an error occurred. I don't know why, but when I rerun the code, it does not occur again. However, it comes up again in the middle of the code.
Error:
PS D:\JARVIS AI> python -u "d:\JARVIS AI\Main\Enhance.py"
Entry Method? Keyboard or Mic: 1
I am Jarvis
Sir: adjust volume
Volume level (0-100): 67
Sir: run plays2.mp3
Jarvis: Terminal or App? 1
Sir: half volume
Exception ignored in: <function _compointer_base.__del__ at 0x000002A548589BC0>
Traceback (most recent call last):
File "C:\Users\dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\__init__.py", line 614, in __del__
self.Release()
File "C:\Users\dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\__init__.py", line 847, in Release
return self.__com_Release()
^^^^^^^^^^^^^^^^^^^^
ValueError: COM method call without VTable
Exception ignored in: <function _compointer_base.__del__ at 0x000002A548589BC0>
Traceback (most recent call last):
File "C:\Users\dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\__init__.py", line 614, in __del__
self.Release()
File "C:\Users\dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes\__init__.py", line 847, in Release
return self.__com_Release()
^^^^^^^^^^^^^^^^^^^^
ValueError: COM method call without VTable
Sir: adjust volume
Volume level (0-100): 44
Then after some time this error come again.
Code:
import os
import datetime
if __name__ == "__main__":
method = method()
if method == "keyboard" or method == "1":
enter = from_keyboard
else:
enter = from_microphone
print("\nI am Jarvis")
speak("I am Jarvis")
while True:
try:
speak("Sir:")
print("\nSir: ", end="")
query = enter()
elif "run" in query:
query = query.replace("run","",1).strip()
if file_locator(query) is not None:
while True:
speak("Sir, In terminal or app?")
print("\nJarvis: Terminal or App? ", end="")
play = enter()
if "app" in play or "2" in play or "default" in play:
default_run(file_locator(query))
break
elif "terminal" in play or "1" in play or "inside" in play:
if any(ext in query for ext in [".mp4", ".mkv"]):
default_run(file_locator(query))
break
elif any(ext in query for ext in [".mp3", ".wav"]):
inbuilt_sound(file_locator(query))
break
elif any(ext in query for ext in [".jpg", ".jpeg", ".png"]):
inbuilt_image(file_locator(query))
break
else:
default_run(file_locator(query))
break
else:
speak("Invalid Input")
print("\nJarvis: Invalid Input")
elif any(keyboard in query for keyboard in ["adjust volume", "half volume", "mute", "max volume", "full volume"]):
if "adjust volume" in query:
while True:
print('Volume level (0-100): ', end="")
speak('Enter the Volume level')
vol = enter()
if vol.isnumeric() and int(vol) >= 0:
vol = int(vol)
adjust(vol / 100)
speak(f"Volume set to {vol} persent")
break
elif vol < 0:
print("\nJarvis: Invalid Input\n")
speak("Invalid Input")
else:
print("\nJarvis: Invalid, Choose a number\n")
speak("Invalid, Choose a number")
elif "mute" in query:
speak("Volume is going muted")
adjust(0)
elif any(keyword in query for keyword in ["max volume", "full volume"]):
adjust(1)
speak("Volume set to max")
elif "half volume" in query:
adjust(0.5)
speak("Volume set to half")
elif "api use" in query:
speak("Showing..")
webbrowser.get(edge_path).open("https://platform.openai.com/account/usage")
comeback()
except Exception as e:
print("Jarvis: ",e)
pass
Adjust Volume Function:
def adjust(vol):
from ctypes import POINTER, cast
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume_object = cast(interface, POINTER(IAudioEndpointVolume))
volume_object.SetMasterVolumeLevelScalar(vol, None)
Video Player Function:
import threading
import playsound
def inbuilt_sound(location):
try:
def sound():
playsound.playsound(location)
sound_thread = threading.Thread(target=sound)
sound_thread.start()
except:
print("Error, try again.")