Monday, December 5, 2016

PowerShell has a speech synthesis class with a speak method (who knew ?) so that the host console can now 'talk' with your user.
I have been having a little fun with it.
#The engine is exposed through the class [System.Speech] by adding the type:
Add-Type -AssemblyName System.Speech
#We then build a named instance (an instance of the class).
#We store ours in the variable tts (text to speech):
#create the instance with new-object
$tts = New-Object System.Speech.Synthesis.SpeechSynthesizer
#Now we can call the speak method on the instance by dot sourcing but before that we need to have a text to read:
$readFileOutLoud = <path to text file>
#I used my config script path location.
#I can now call the method:
$tts.Speak($readFileOutLoud)

It worked flawlessly.
Could we just as readily include any custom spoken out-put through means of a variable that stores our custom message ?
$myPhrase = {"PowerShell ROCKS"}
#test our variable
#$myPhrase shows the expected output "PowerShell ROCKS"
#call the speak method:
$tts.Speak($myPhrase)
Success !
You can use any variable from your current session with the correct data type or you can create one for your use
and that, that is all, just 'to cool for school'.
#Let's build a function that will both tell my user something and write the same output to the console host:
function showAndTell
{$myPhrase,
$tts.Speak($myPhrase)
}
#call the function by typing its' name
#showAndTell
That's pretty cool.
But not cool enough.
Include a little boiler-plate so that the custom in session function is findable to PowerShell's' get-Help and Get-Command functionalities:
function showAndTell
{<#
 .SYNOPSIS
  The function is an advanced command that out-puts both a verbose message and an audio message.
 .DESCRIPTION
  The function both 'speaks' to your user and outputs to the
  console host screen your custom message.
 .PARAMETER ParameterA
  The description of the ParameterA parameter.
 .PARAMETER ParameterB
  The description of the ParameterB parameter.
 .EXAMPLE
  type: showAndTell
  This example shows how to run the command.
 .INPUTS
  System.Object
 .OUTPUTS
  The function writes an informational message to the
  console host and outputs an audio message to your user.
 .NOTES
  The function is executed in serial fashion as
  a first in first out operation.
   #functionName : showAndTell
   #codeAuthor   : Steven McKnight
   #Company      : MpMxLabs
   #ParallelLevel : OrderOneSerial (-s-)
   #Source       : Cyberex
   #written at   : Piety Hill
   #Copyright (c) : 2016
 .ROLE
  OrderOne
 .COMPONENT
  Dependencies
 .FUNCTIONALITY
  Serial (-s-)
 .LINK
  about_Functions_Advanced
 .LINK
  about_Comment_Based_Help
 .LINK
  about_Functions
#>
$myPhrase,
$tts.Speak($myPhrase)
}
There you have it. Deeply cool.

I want to thank #Ryan Mattfield for his fine post here of
previous that got me to partying on text to speech.

Sunday, September 18, 2016

What is a string Value....?

So then what is a string value..?
Unary operators and parathetical statements are strings indeed and
they are central in our discovery as to..."What is a string value ?".
To the system everything is an object. The initial object is termed <void>. Void is not nothing.It is a model.
It is a blueprint of an idea.The idea is one of a space for action.
For example, in Mathematics the plus sign ("+") denotes the operation 'addition'....
In operations like addition, take 2+3=5 for instance, the place of action is with the unary operator at the begining of the equation
2[+]3 followed by the '=' operator [=] followed by the result [5]. Note that it is a sequence of states.
The unary operator "+", the plus sign, does one thing (it is unary) and operates upon the data stores in one way only.
No matter the numbers being added together the operation produces the sum of the munbers.
In commputer programming as in Mathematics certain sigils denote something other and that other is concretely defined.
In computer science as in Math the paranthesis () is mapped to the idea or concept to 'do this first' within the operation.
The string composed of the two sigils in certain arangement "()" tells us how to proceed...do this first.
The two marks thus placed are signified as an expression telling us and the system without ambiguity what is intended in the order of operation.
So then the results of 9/(4+5)+5 is: 6, where-as the results of 9/4+(5+5) is: 12.25. This is fundemental to the correctness of our programs.
The square brackets also denote or are mapped to an idea.. that of a schema or model of a space to define unambigousely a specific data structure.
[<TypeName>]...read CLASS is a model of, or, blueprint for an instance of a thing, but,
it's not the actual thing...just a specification for describing the thing (the CLASS). Those something
elses are again and again and again data structures or stores and each is an object.
[]... is not a data structure. It is a place where there is a data structure.....To the system everything is a data structure
to be operated upon or a place where the operations "()" and data "[]" reside.... a kind of of conceptual <void> where stuff happens
or things can be built like models of objects and the objects themselves and these objects can then interact in meaningful and powerfull ways.

What is a string value...?

What is a string value ?
Seems like a fair question. Five simple words.

Computational thinking can help us to solve this most interesting question.
Type into the shell your name.
An error message will be displayed. In my example the host console screen displays this error message:
...
Steve : The term 'Steve' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Steve
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (Steve:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The error message is very informative.
First it echoes the input requesting action from the system. In my example it outputs my name Steve followed
by a colon separator and the familiar "The term 'steve' is not recognized as the name of a cmdlt, function, script file,
or operable program..." Notice that in the output of the error message that the data expressed in the part, 'The term 'Steve', is
in single quotes. A clue.
The experience of PowerShell is interactive. Interactive means that PowerShell is doing at least three things. It is
accepting input, interprting it, and operating upon it. This is fundemental I know, but, it is not trivial. It is interactive.
The error message encourages us to '...and try again.'
So we type: 'Steve' (with single quotes) and PowerShell quickly echoes to the hosts console screen: Steve
All is right with the world.
I then type '55555' (with the single quote marks) and the engine echoes to the hosts console monitor: 55555
As was to be expected.
I type 55555 (with no single qoute marks) and the engine displays 55555.
I type: 12 + 2.
The engine displays 14.
Hmmmm.