pytronlinks library¶
Submodules¶
Pytron - The MVC Links Interface¶
Links for Python. Interact with Links from your scripts!
-
class
pytronlinks.client.
Client
(path=None, port='54657', key='ABC1234', ip='localhost')¶ Bases:
object
Main Pytron Client v.0.3.9
Example: import pytronlinks
ai = pytronlinks.Client()
-
CallCommand
(command)¶ Calls any non-dynamic commands and returns the response from links :param command: Any command that doesn’t contain a wordlist or function :return: Returns the response from Links as a string
-
Get
(var_name)¶ Gets a variable saved in the ‘LINKSCustomizationXMLUserVariables.xml’ file.
Parameters: var_name – Name of variable to get the value of Returns: Returns the value of the variable
-
GetConfirmation
(trigger_var='Answer', confirm=None, on_yes=None, on_no=None, timeout=10)¶ Parameters: - trigger_var –
- confirm –
- on_yes –
- on_no –
- timeout –
Returns:
-
GetGrammarList
(data_type='XML')¶ Returns a list of all callable commands. Use with write_commands_to_file to create a file containing all the available grammars to use as a reference.
Parameters: data_type – Returns:
-
GetWord
(wordlist, grammar, column)¶ Returns wordlist items by grammar (line) and column name
Parameters: - wordlist – File name of wordlist ( file type not needed )
- grammar – Basically the line index. ( ie: first column )
- column – Column to return value from ( name or index )
Returns: Returns True or False
-
LoqSpeak
(text, volume, rate, ai_name)¶ Sends a ‘Loquendo by Nuance’ speech command ( requires Nuance Loquendo voices )
Parameters: - text – Text to be spoken ( with all the syntax they use, better make it raw, ie: r’text’ )
- volume – Volume 0 - 100
- rate – Unsure of rate ( needs testing )
- ai_name – Name of tts Voice ( case sensitive )
-
SayAs
(before, data, content, after='')¶ This function is only for speech. Will speak the appropriate way for the given data type. ( See example )
Parameters: - before – In the example, the before string is “The phone number is” ( can be blank )
- after – In the example, the after string is “how cool is that?” ( defaults to blank )
- data – Data to be spoken as
- content – see https://msdn.microsoft.com/en-us/library/system.speech.synthesis.sayas(v=vs.110).aspx )
Example:
ai.SayAs(r”The phone number is”,”18001239874”,”Telephone”,”how cool is that?”)
-
Set
(var_name, var_value)¶ Sets a variable in the ‘LINKSCustomizationXMLUserVariables.xml’ file.
Parameters: - var_name – Name of variable
- var_value – Value to set
-
SetSpeechConfig
(name, vol, rate)¶ Config a certain speakers parameters
Parameters: - name – Name of tts speaker ( ex: IVONA Brian ) case sensitive
- vol – Volume 0 - 100
- rate – Speech rate -10 - 10
-
SetSpeechVoice
(name)¶ Set active speaker
Parameters: name – Name of tts speaker ( ex: IVONA Brian ) case sensitive
-
SetSpeechVolume
(vol)¶ Sets system wide speech volume
Parameters: vol – 0 - 100
-
SpeakEx
(phrase, name, vol, rate, delay, sys_or_voice_vol='voice')¶ Speaks using specified values
Parameters: - phrase – Phrase to be spoken
- name – Name of tts speaker ( ex: IVONA Brian ) case sensitive
- vol – 0 - 100
- rate – Fast - Slow
- delay – Initial delay
- sys_or_voice_vol – Use system wide volume or ai’ set volume
-
SpeakExSysVolAsync
(phrase, VoiceVolume, VoiceRate, phraseDelay, VoiceName)¶ Asynchronous speech
Parameters: - phrase – Phrase to be spoken
- VoiceVolume – 0 - 100
- VoiceRate – -10 - 10
- phraseDelay – Delay between next speech ( ex: 0.8 )
- VoiceName – Ai name ( case sensitive )
-
SpeakExSysVolSync
(phrase, VoiceVolume, VoiceRate, phraseDelay, VoiceName)¶ Synchronous speech
Parameters: - phrase – Phrase to be spoken
- VoiceVolume – 0 - 100
- VoiceRate – -10 - 10
- phraseDelay – Delay between next speech ( ex: 0.8 )
- VoiceName – Ai name ( case sensitive )
-
StopVoiceByIdentifier
(identifier, ResponseOnSuccess)¶ Stops voice by Identifier, which is only set in tasks atm - uses tasks name
Parameters: - identifier – Task name
- ResponseOnSuccess – AIs response
-
StopVoiceByName
(name, ResponseOnSuccess)¶ Stop the current speaker by AI name
Parameters: - name – Name of ai ( case sensitive )
- ResponseOnSuccess – What the ai says after being silenced
-
config
()¶ Config itself doesn’t work yet and for now just prints this handy - Volume and Rate Cheat-Sheet -
- Usage:
- import pytronlink ai = pytronlinks.Client() ai.config()
* The following strings or nums can be used to set voice parameters for any speak/task function. *
- Volume:
- Silent = 0, ExtraSoft <= 20, Soft <= 4, Medium <= 60, Loud <= 80, ExtraLoud <= 100 (default) Leave it blank for default
- Rate:
- NotSet = 0 ExtraFast = 1 Fast = 2 Medium = 3 (default) Slow = 4 ExtraSlow = 5 Leave it blank for default
-
custom
(string)¶ - Insert your own Links Action Commands -
- Anything you can put in Links Action bar, you can put in here! This would be useful for new testing new Links functions that haven’t made it to here yet. See example.
Parameters: string – See example.. Example -
import pytronlinks
ai = pytronlinks.Client()
ai.custom(r’[Set(“Last Subject”, “pytron is the coolest”)]’) ai.custom(r’[Speak(“[Get(“Last Subject”)]”)]’)
-
emulate_speech
(command)¶ Sends an Emulate Speech Command -
Parameters: command – This is the speech for the command you want to emulate Will call the command as if you had spoken to links directly *Listening must be enabled on Links! ( ie: Hard listening mode not disabled )
Example: import pytronlinks
ai = pytronlinks.Client()
ai.emulate_speech(“what time is it”) ai.emulate_speech(“play music”)
-
listen
(var_name='Pytron', freq=0.2)¶ Check out the example to see how you could use this. This is probably the most powerful feature.
Parameters: - var_name – Name of the Variable you want to “listen” to. OPTIONAL. Defaults to ‘Pytron’
- freq –
Delay ( in seconds ) between checks. OPTIONAL. Defaults to 0.2 seconds
** Make a command in links social tab like this **
Command: Links {speech=test_dictation} Response: [Set(“Pytron”, {speech})] Profile: Main
Command: {answer=Answer} Response: [Set(“Confirm”, {{answer}})] Profile: Main
- And use the dictation in Pytron with the script below.. ( Ctrl-c to quit )
- v v v v v
Example: import pytronlinks
ai = pytronlinks.Client()
def main():
dictation = ai.listen() if not dictation:
break
confirm = ai.GetConfirmation(confirm=’Did you say - {}?’).format(dictation) if not confirm:
break
results = some_crazy_function(dictation) if not results:
break
ai.talk(results)
- try:
- while True:
main()
- except KeyboardInterrupt:
pass
-
static
strip_bad_chars
(string)¶ - Cleans up some speech elements.. Replaces some things that may otherwise
- mess up the url request to Links.. ( this function is ugly and needs a bag on its head )
-
static
strip_non_ascii
(string)¶ Can be used to remove non-ascii characters from a string.
Parameters: string – String with non-ascii characters Returns: Cleaned up string
-
talk
(text)¶ Speaks through Links
Parameters: text – String to be spoken
Example: import pytronlinks
ai = pytronlinks.Client() ai.talk(“Links is the best!”)
-
write_commands_to_file
(commands)¶ Writes a list of commands to a file in rst format.
Parameters: commands – List of commands returned bt GetGrammarList function Returns: Returns True or Exceptions
-