i am the funny
 

 I AM THE FUNNY!!!

So, we have some basic scripts that I have put up, lets talk about adding them into a GUI. Now, I am going to do something very simple this time around, it will be an input box where you enter words to say and your computer will say them to you.
So like I said, nothing to complex. But, I will be doing the form as a function, this is because you will then be able to pretty much copy and past this function into anything and just call it when ever you need an input box.
I mean, lets be honest, it makes more sense to not refresh the form/gui each time, but hey, this makes it usable in other places, so ... justified.. why am i now thinking about Justin Timberlake?...

<#
.SYNOPSIS
   Gui which allows you to type in words which it than converts to speach
#>

Function IamFunction ([string]$TitleOfForm, [string]$WhatYouWant, [string]$AnExample){
    
    # Creates an icon that shows up on the screen
    $iconBase64 = 'AAABAAEAMjEAAAEACACkDwAAFgAAACgAAAAyAAAAYgAAAAEACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAEBAQACAgIAAwMDAAQEAAAEBAMABAQEAAUFBQAGBgYABwcHAAgICAAJCQkACgoKAAsLCwANDQUADAwLAAwMDAAMDA0ADQ0NAAICOQAODg4ADw8PABAQEAAREREAEhISABMTEwAUFBQAFRUVABYWFgAXFxcAGBgYABkZGQAaGhoAGxsbABwcHAAICGkAHR0dAB4eHgAfHx8AICAgACEhIQAiIiIAIyMjAAUFlQAkJCQAJSUlAAICqQAmJiYAKCgoACkpKQAqKioALCwmACsrKwAsLCwALS0tAC4uLgAvLy8AMDAwADExMQAyMjIAODgcADY2JAAAAOwANDQsADIyNAA1NSkAMTE4ADQ0LQAzMzEANjYmADIyNQA1NSoAMTE5ADQ0LgAwMD0AMzMyADY2JwAvL0EAMjI2ADU1KwAxMToANDQvADc3JAAwMD4AOjoZACkpWAAzMzMANjYoADIyNwArK1EANTUsAC4uRgAxMTsANDQwAC0tSgAmJmQAMDA/ADMzNAA2NikALy9DADIyOAArK1IANTUtADExPAAqKlYANDQxAC0tSwAwMEAAKSlaADMzNQAyMjkAKytTADU1LgAkJG0ALi5IACcnYgAxMT0ALS1MACYmZgAwMEEAKSlbACwsUAA2NisAJSVqAC8vRQ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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
    $iconBytes       = [Convert]::FromBase64String($iconBase64)
    $stream          = New-Object IO.MemoryStream($iconBytes, 0, $iconBytes.Length)
    $stream.Write($iconBytes, 0, $iconBytes.Length)
    $iconImage = [System.Drawing.Image]::FromStream($stream, $true)
    
    # here we are setting up the form and it's location 
    $form = New-Object System.Windows.Forms.Form
    $form.Text = $TitleOfForm # Form title which gets filled in when you call the function
    $form.Size = New-Object System.Drawing.Size(300,200)
    $form.StartPosition = 'CenterScreen'
    $form.Icon = [System.Drawing.Icon]::FromHandle((New-Object System.Drawing.Bitmap -Argument $stream).GetHIcon())

    # what do you know, it is an OK button! and its location on the form
    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Point(75,120)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = 'OK'
    $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
    $form.AcceptButton = $OKButton
    $form.Controls.Add($OKButton)

    # Same as the ok button, but this time we are cancelling things
    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Point(150,120)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = 'Cancel'
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    $form.CancelButton = $CancelButton
    $form.Controls.Add($CancelButton)

    # label for th input box
    $label = New-Object System.Windows.Forms.Label
    $label.Location = New-Object System.Drawing.Point(10,20)
    $label.Size = New-Object System.Drawing.Size(280,30)
    $label.Text = $WhatYouWant #'Please enter the information in the space below:'
    $form.Controls.Add($label)
    
    # it'sa me, mar...an input box
    $textBox = New-Object System.Windows.Forms.TextBox
    $textBox.Location = New-Object System.Drawing.Point(10,50)
    $textBox.Size = New-Object System.Drawing.Size(260,20)
    $textBox.Text = $AnExample
    $form.Controls.Add($textBox)
    
    # puts form at the front of everything
    $form.Topmost = $true
    
    # selects the text box so you can just start typing
    $form.Add_Shown({$textBox.Select()})
    
    # gets which button was pressed
    $result = $form.ShowDialog()
    
    # if statement to deal with the buttons
    if ($result -eq [System.Windows.Forms.DialogResult]::OK){
        $FunctionReturn = $textBox.Text
    }ElseIf($result -eq [System.Windows.Forms.DialogResult]::CANCEL){
        $FunctionReturn = "cancel"
    }
    return $FunctionReturn
}

Function IWillSpeak ([string]$Words){
    $object = New-Object System.Speech.Synthesis.SpeechSynthesizer
    #You can use this to list the voices available on your computer and then select the voice in the next line
    #$object.GetInstalledVoices().VoiceInfo
    $object.SelectVoice("Microsoft David Desktop")
    $object.Speak($Words)
}

# Important things you need to do to build an input box
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Speech

do{
    $Result = IamFunction "Talk to me:" "Please enter some words:" "e.g: I can speak"

    write-host $Result
    
    # Switch to tell the script what to do with the info it just got from the input box
    switch($Result){
        "e.g: I can speak"{
            write-host "wow..."
            IWillSpeak "Now that is just lazy... i mean... did you even try?"
            write-host "let's do it all again!"
        }
        "cancel"{
            Write-Host "exiting"
        }
        default{
            write-host "working"
            IWillSpeak $Result
            write-host "let's do it all again!"
        }
    }

}Until($Result -eq "cancel")