• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

MM and Custom Python Script

Scheduled Pinned Locked Moved General Discussion
7 Posts 2 Posters 1.8k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    Extra
    last edited by Jan 22, 2022, 9:54 PM

    Hello,

    I just discovered Magi Mirror and I absolutely LOVE IT! It’s easy to use and it looks awesome!

    So I have a custom python scripts that I would love to run alongside my Magic Mirror.

    My Python script is a virtual voice assistant that can do google searches, conversions, and more. Anyways, I would love to have that running in the back round while MM is running, instead of using 2 separate Rpi’s. Is that possible? If so, how?

    One more thing, my python script has print statements that print to the terminal but I was wondering if they can be rerouted to the compliments scripts that way the results would display on MM then fade out( and the compliments would then show).
    Is that possible as well and if so, how can it be done?

    Thanks in advance?

    S 2 Replies Last reply Jan 22, 2022, 10:07 PM Reply Quote 0
    • S Away
      sdetweil @Extra
      last edited by Jan 22, 2022, 10:07 PM

      @extra see my PythonPrint module which launches a python script (once and long running) or
      end and needs to be rerun (get status of something now)

      https://github.com/sdetweil/MMM-PythonPrint

      so, the python script would hear and translate voice to text and send and module would collect and send to browser side…

      one could then do some action or sendNotification(???, text)

      so do so action on another module

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      E 1 Reply Last reply Jan 23, 2022, 12:16 AM Reply Quote 0
      • S Away
        sdetweil @Extra
        last edited by Jan 22, 2022, 11:04 PM

        @extra my code can be used to display, and fade out would be a css setting

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • E Offline
          Extra @sdetweil
          last edited by Jan 23, 2022, 12:16 AM

          @sdetweil So your PythonPrint module will let me run my python script as MM is running, correct?

          And how would I get the print statements to appear like the compliments (same font size, transitions. And if I have 2 sentences that need to be displayed it breaks up the words and fades them in/out in order)?

          So basically, I press a button(which unmutes my mic), say my command, and have the results displayed to MM.

          Here’s a sample of my python script:

          #-------------------------------------------------------------------------------------
                                      #Search Wikipedia (General Info)
              #-------------------------------------------------------------------------------------
              if ('weather' not in command): 
                  if ('who is' in command) or ('what is the' in command) or ('what is a' in command) or ("what is" in command):
                      if ('time' not in command):
                          if ('news' not in command):
                              speak('Searching Wikipedia...')
                              command = command.replace("who is","")
                              command = command.replace("what is the","")
                              command = command.replace("what is a","")
                              command = command.replace("what is","")
                              results = wikipedia.summary(command, sentences = 2)
                              #----------------------
                              #Auto typing animation:
                              print("Baxter: ", end="")
                              for i in results:
                                  sys.stdout.write(i)
                                  sys.stdout.flush()
                                  time.sleep(0.05)
                              print("\n")
                              #----------------------
                              speak(results) 
              #-------------------------------------------------------------------------------------
                              #Search Wolfram Alpha (Math/Conversions, Definitions)
              #-------------------------------------------------------------------------------------
              if ('weather' not in command):
                  if ('news' not in command):
                      if ('calculate' in command) or ("what's" in command) or ('define' in command):
                          speak('Searching Wolfram Alpha...')
                          command = command.replace("calculate","")
                          command = command.replace("what's","")
                          command = command.replace("define","")
                          # Wolframalpha App Id
                          appId = ''
                          # Wolfram Instance
                          client = wolframalpha.Client(appId)
                          res = client.query(''.join(command))
                          results = next(res.results).text
                          #----------------------
                          #Auto typing animation:
                          print("Baxter: ", end="")
                          for i in results:
                              sys.stdout.write(i)
                              sys.stdout.flush()
                              time.sleep(0.05)
                          print("\n")
                          #----------------------
                          speak(results) 
          
          S 1 Reply Last reply Jan 23, 2022, 12:38 AM Reply Quote 0
          • S Away
            sdetweil @Extra
            last edited by Jan 23, 2022, 12:38 AM

            @extra my code puts the stdout output of the python script onto the page

            you just need to specify css classes in custom.css

            try the sample… it launches a python script that runs forever and prints output, the node_helper gets it and sends to module

            module displays…

            			wrapper.innerHTML = this.config.message;
            			wrapper.className += "PythonPrint"
            

            so just set the class values in custom.css

            .MMM-PythonPrint .PythonPrint { 
               font-size:24px;
               color: yellow;
            }
            

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            E 1 Reply Last reply Jan 23, 2022, 1:08 AM Reply Quote 0
            • E Offline
              Extra @sdetweil
              last edited by Extra Jan 23, 2022, 1:17 AM Jan 23, 2022, 1:08 AM

              @sdetweil Thanks will do. I just got a little confused, thanks for the clarification.

              S 1 Reply Last reply Jan 23, 2022, 4:26 PM Reply Quote 0
              • S Away
                sdetweil @Extra
                last edited by Jan 23, 2022, 4:26 PM

                @extra u can use my code as the base for what u need, but it does 95%

                splitting lines

                easy in JavaScript, split()

                how to handle the different lines… that’s your design and implementation
                my code assumes one blob of text.

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  1/7
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy