The tutorial for today is a simple script for python user.
If you run this python script in your folder you will get an python shortcut to the python and the python to the Context Menu in Windows 10.
The Context Menu can be used with right click from your mouse, see the screenshot.
This script can also be used with any executable if you make some changes.
Caption None
Description None
InstallDate None
Name None
Status None
StartTime 20190530105325.022532+180
AuthenticationPackage LiveSSP
LogonId 8291403
LogonType 2
Caption None
Description None
InstallDate None
Name None
Status None
StartTime 20190530105325.022532+180
AuthenticationPackage LiveSSP
LogonId 8291220
LogonType 2
You can read info with this python module.
For example, the output tells me aboutLogonType.
You’ll see type 2 logons when a user attempts to log on at the local keyboard and screen whether with a domain account or a local account from the computer.
The tutorial is about win32com python module using the python 3.7.3.
First exameple is simple:
import sys
import win32com.client
from win32com.client import constants
speaker = win32com.client.Dispatch("SAPI.SpVoice")
print ("Type word or phrase, then enter.")
while 1:
text_to_say = input("> ")
speaker.Speak(text_to_say)
Let's run it.
The Microsoft Speech SDK to speak what you type in from the keyboard.
C:\Python373>python.exe speak_001.py
Type word or phrase, then enter.
> this is a test
The next example is more complex and uses speech recognition to create outputs.
You can change this example to execute tasks.
# This is a sample code for speech recognition using the MS Speech API
from win32com.client import constants
import win32com.client
import pythoncom
"""
You will see a voice say: Started successfully
The you need to start the speech recognition tool.
After running this, then saying "One", "Two", "Three" or "Four" should
display "You said One" etc on the console.
"""
class SpeechRecognition:
""" Initialize the speech recognition with the passed in list of words """
def __init__(self, wordsToAdd):
# For text-to-speech
self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
# For speech recognition - first create a listener
self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
# Then a recognition context
self.context = self.listener.CreateRecoContext()
# which has an associated grammar
self.grammar = self.context.CreateGrammar()
# Do not allow free word recognition - only command and control
# recognizing the words in the grammar only
self.grammar.DictationSetState(0)
# Create a new rule for the grammar, that is top level (so it begins
# a recognition) and dynamic (ie we can change it at runtime)
self.wordsRule = self.grammar.Rules.Add("wordsRule",
constants.SRATopLevel + constants.SRADynamic, 0)
# Clear the rule (not necessary first time, but if we're changing it
# dynamically then it's useful)
self.wordsRule.Clear()
# And go through the list of words, adding each to the rule
[ self.wordsRule.InitialState.AddWordTransition(None, word) for word in wordsToAdd ]
# Set the wordsRule to be active
self.grammar.Rules.Commit()
self.grammar.CmdSetRuleState("wordsRule", 1)
# Commit the changes to the grammar
self.grammar.Rules.Commit()
# And add an event handler that's called back when recognition occurs
self.eventHandler = ContextEvents(self.context)
# Announce we've started
self.say("Started successfully")
"""Speak a word or phrase"""
def say(self, phrase):
self.speaker.Speak(phrase)
"""
The callback class that handles the events raised by the speech object.
"""
class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
"""Called when a word/phrase is successfully recognized and is
found in a currently open grammar """
def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
newResult = win32com.client.Dispatch(Result)
print ("You said: ",newResult.PhraseInfo.GetText())
if __name__=='__main__':
wordsToAdd = [ "One", "Two", "Three", "Four" ]
speechReco = SpeechRecognition(wordsToAdd)
while 1:
pythoncom.PumpWaitingMessages()
I remembered my days when I played with visual script.
Later I discovered python on linux and I realized that it's as good if not better.
Then I made a script that display the character Merlin said something.
Today I'll try the same thing with python.
First you have to install python module called win32com.
For this we use installer from here.
It automatically installs python 2.6 folder, see picture below...
To begin to build script.
For this we need to read the MSDN documentation least, see here.
The first step required is to import module module ...
import win32com
from win32com import client
from win32com.client import constants
Access file .acs and declare a variable named vrajitor to use it.