Skip to main content

Featured

Solving Economic Crisis Without Work-From-Home: A Systems Approach to Resource Prioritization

  1. The Economic Problem: Diagnosing the Crisis Type 1.1 Crisis Typology and Sector Dynamics Currency crises typically emerge from one or more of these imbalances: Current account deficits — Imports exceed exports; forex drains to cover the gap Capital account withdrawal — Foreign investors exit; hot money leaves Inflation-driven overvaluation — Real exchange rate strengthens despite nominal devaluation Debt servicing burden — External debt payouts drain reserves faster than exports can cover The empirical record shows that currency crises are sectoral crises —not aggregate demand crises. When Argentina devalued 75% in 2001, the economy contracted 10.9%, but manufacturing capacity utilization recovered within 18 months because input costs fell (Hausmann & Velasco, 2002). When Vietnam reformed in 1986, manufacturing capacity expansion drove recovery before demand-side effects materialized. Critical insight: Resource reallocation works when the constraint is supply-sid...

Python Code for Basic Assistant

 This Python script is a voice-controlled personal assistant that performs various tasks based on voice commands. It utilizes the `speech_recognition` library for speech recognition, `pyttsx3` for text-to-speech functionality, and other modules for performing actions like opening programs, searching Google, shutting down the computer, checking the battery percentage, searching YouTube, and playing music.


Here's a breakdown of the key functions:


1. `speak(text)` function:

   - Uses the `pyttsx3` library to convert text into speech.

   - Initializes the text-to-speech engine, speaks the given text, and waits for the speech to finish.


2. `open_program(program_name)` function:

   - Uses the `subprocess` module to open a specified program.

   - Finds the path of the program using `shutil.which`.

   - Uses `subprocess.Popen` to open the program in a new process.


3. `search_google(query)` function:

   - Opens the default web browser to perform a Google search based on the given query.


4. `shutdown_computer()` function:

   - Initiates the shutdown process for the computer using the `subprocess.run` method.


5. `show_battery_percentage()` function:

   - Uses the `psutil` library to get information about the battery status.

   - Retrieves the battery percentage and speaks it.


6. `search_youtube(query)` function:

   - Opens the default web browser to perform a YouTube search based on the given query.


7. `play_music(query)` function:

   - Opens the default web browser to search for music on YouTube based on the given query.


8. `main()` function:

   - Initializes a speech recognizer from `speech_recognition`.

   - Captures audio from the microphone and adjusts for ambient noise.

   - Uses Google's speech recognition service to convert the audio into text.

   - Parses the recognized text to identify commands and performs corresponding actions.

   - Handles unrecognized commands and errors gracefully.


9.   Main Block (`__name__ == "__main__"`):

   - Calls the `main()` function to start the voice-controlled personal assistant.


To use the personal assistant, run the script, and it will listen for your voice commands. You can give commands such as "Open Chrome," "Search Google for Python tutorials," "Shutdown," "Battery," "Search YouTube for funny cats," or "Play music." The assistant will respond to your commands and perform the requested actions.



import os
import subprocess
import webbrowser
import psutil
import pyttsx3
import speech_recognition as sr
import shutil  # Add this import for the shutil module

# Rest of your code
def speak(text):
    engine = pyttsx3.init()
    engine.say(text)
    engine.runAndWait()

def open_program(program_name):
    try:
        program_path = shutil.which(program_name)
        if program_path:
            subprocess.Popen([program_path])
            speak(f"Opening {program_name}")
    except Exception as e:
        speak(f"Could not find program: {program_name}")

def search_google(query):
    speak(f"Searching Google for {query}")
    webbrowser.open(f"https://www.google.com/search?q={query}")

def shutdown_computer():
    speak("Shutting down computer")
    subprocess.run(["shutdown", "/s", "/t", "0"])

def show_battery_percentage():
    battery = psutil.sensors_battery()
    percent = battery.percent
    speak(f"The battery is at {percent} percent")

def search_youtube(query):
    speak(f"Searching YouTube for {query}")
    webbrowser.open(f"https://www.youtube.com/results?search_query={query}")

def play_music(query):
    speak(f"Playing {query}")
    webbrowser.open(f"https://www.youtube.com/results?search_query={query}")

def main():
    recognizer = sr.Recognizer()

    with sr.Microphone() as source:
        print("Listening for a command...")
        recognizer.adjust_for_ambient_noise(source)
        audio = recognizer.listen(source)

    try:
        command = recognizer.recognize_google(audio).lower()
        print("You said:", command)

        if "open" in command:
            program_name = command.split("open ")[1]
            open_program(program_name)
        elif "search google for" in command:
            search_query = command.replace("search google for", "").strip()
            search_google(search_query)
        elif "shutdown" in command:
            shutdown_computer()
        elif "battery" in command:
            show_battery_percentage()
        elif "search youtube for" in command:
            youtube_query = command.replace("search youtube for", "").strip()
            search_youtube(youtube_query)
        elif "play" in command:
            music_query = command.replace("play", "").strip()
            play_music(music_query)
        else:
            speak("Command not recognized. Please try again.")

    except sr.UnknownValueError:
        speak("Sorry, I couldn't understand what you said. Please try again.")
    except sr.RequestError as e:
        speak(f"There was an error connecting to the Google Speech Recognition service. Please try again later.")

if __name__ == "__main__":
    main()

Comments

Popular Posts