<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>use powershell voice Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/use-powershell-voice/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/use-powershell-voice/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Fri, 02 Apr 2021 19:01:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Powershell Text To Speech &#124; How To Guide</title>
		<link>https://thesysadminchannel.com/powershell-text-to-speech-how-to-guide/</link>
					<comments>https://thesysadminchannel.com/powershell-text-to-speech-how-to-guide/#respond</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Fri, 02 Apr 2021 00:08:00 +0000</pubDate>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[powershell speech to text]]></category>
		<category><![CDATA[use powershell voice]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=2154</guid>

					<description><![CDATA[<p>Today we&#8217;re going to go over how to use Powershell text to speech. This means that we can write a bunch of text and have Powershell basically say the words out loud through your speakers. In some cases this might&#8230; <a href="https://thesysadminchannel.com/powershell-text-to-speech-how-to-guide/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/powershell-text-to-speech-how-to-guide/">Powershell Text To Speech | How To Guide</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today we&#8217;re going to go over how to use <strong>Powershell text to speech</strong>.  This means that we can write a bunch of text and have Powershell basically say the words out loud through your speakers.</p>
<p>In some cases this might be useful to get an audio reminder for something or even if you want to have text read back to you.  If that&#8217;s the case, we&#8217;ll share how use this feature.  </p>
<h2>Preparing Powershell to use Speech</h2>
<p>To get started we&#8217;ll need to make sure we utilize the proper .NET Frameworks on your machine.  The ones we need to focus on are the <code>System.Speech</code> type assembly.  This will utilize the <code>SpeechSynthesizer</code> object to be able to use the built in voices that we&#8217;re looking for to use Powershell voice.</p>
<pre class="brush: powershell; title: ; notranslate">

Add-Type -AssemblyName System.Speech
$Speech = New-Object System.Speech.Synthesis.SpeechSynthesizer

</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/03/Add-System.Speech-Type-Assembly.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/03/Add-System.Speech-Type-Assembly.png" alt="Add System.Speech Type Assembly" width="900" height="414" class="aligncenter size-full wp-image-3069" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/03/Add-System.Speech-Type-Assembly.png?v=1616633090 900w, https://thesysadminchannel.com/wp-content/uploads/2021/03/Add-System.Speech-Type-Assembly-768x353.png?v=1616633090 768w" sizes="(max-width: 900px) 100vw, 900px" /></a></p>
<p>&nbsp;</p>
<h2>Using Text to Voice Manually</h2>
<p>Before I dive into the script I wanted to showcase some items that you should probably be aware of behind the scenes.  For starters, there are 2 built-in voices that come equipped with Windows 10.  They&#8217;re named David and Zira. </p>
<p>David is the male voice while Zira is the female.  In my opinion I like hearing Zira so I set it as the default in the script, but you&#8217;re more than welcome to change it up.</p>
<p>Now that we have the SpeechSynthesizer object created and set in the $Speech variable, we can check out some of the properties and methods that belong to it.  For starters, we can pipe the $Speech to Get-Member and view the available methods there .</p>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/04/Powershell-Voice-Get-Member.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/04/Powershell-Voice-Get-Member.png" alt="Powershell Voice Get Member" width="1178" height="860" class="aligncenter size-full wp-image-3076" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/04/Powershell-Voice-Get-Member.png?v=1617319582 1178w, https://thesysadminchannel.com/wp-content/uploads/2021/04/Powershell-Voice-Get-Member-1024x748.png?v=1617319582 1024w, https://thesysadminchannel.com/wp-content/uploads/2021/04/Powershell-Voice-Get-Member-768x561.png?v=1617319582 768w" sizes="(max-width: 1178px) 100vw, 1178px" /></a><br />
&nbsp;</p>
<p>Next we want to be able to see what voices are available to us so we&#8217;ll use the GetInstalledVoices method like so.</p>
<pre class="brush: powershell; title: ; notranslate">
$Speech.GetInstalledVoices() | select -ExpandProperty VoiceInfo | select Name, Gender, Description
</pre>
<p>&nbsp;<br />
Finally, if we wanted to change the voice from one voice to another, e.g. David to Zira, we can use the SelectVoice method.</p>
<pre class="brush: powershell; title: ; notranslate">
$Speech.SelectVoice(&quot;Microsoft Zira Desktop&quot;)
</pre>
<p><a href="https://thesysadminchannel.com/wp-content/uploads/2021/04/Get-Installed-Voices-Powershell1.png" target="_blank" rel="noopener"><img decoding="async" src="https://thesysadminchannel.com/wp-content/uploads/2021/04/Get-Installed-Voices-Powershell1.png" alt="Get Installed Voices Powershell1" width="1082" height="324" class="aligncenter size-full wp-image-3079" srcset="https://thesysadminchannel.com/wp-content/uploads/2021/04/Get-Installed-Voices-Powershell1.png?v=1617320064 1082w, https://thesysadminchannel.com/wp-content/uploads/2021/04/Get-Installed-Voices-Powershell1-1024x307.png?v=1617320064 1024w, https://thesysadminchannel.com/wp-content/uploads/2021/04/Get-Installed-Voices-Powershell1-768x230.png?v=1617320064 768w" sizes="(max-width: 1082px) 100vw, 1082px" /></a><br />
&nbsp;</p>
<h3>Putting Powershell Speech All Together</h3>
<p>The last thing we need to do it setup the actual text so Powershell knows what to say. We&#8217;ll put our message in a $Message variable and insert that into the Speak method.</p>
<pre class="brush: powershell; title: ; notranslate">
$Message = 'This is awesome.  We now know how to use Powershell Text To Speech'
$Speech.Speak($Message)
</pre>
<h2>Powershell Text To Speech Script</h2>
<p>Now that we know how to do it manually, let&#8217;s leverage Powershell to do this automatically.  After all, Powershell is a scripting language so it&#8217;s really suitable for our situation.  We&#8217;ll name this function <strong>New-TextToSpeechMessage</strong>.</p>
<pre class="brush: powershell; title: ; notranslate">

Function New-TextToSpeechMessage {
&lt;#
.SYNOPSIS
    This will use Powershell to have a message read out loud through your computer speakers.


.NOTES
    Name: New-TextToSpeechMessage
    Author: theSysadminChannel
    Version: 1.0
    DateCreated: 2021-Feb-28

.LINK
    https://thesysadminchannel.com/powershell-text-to-speech-how-to-guide -

.EXAMPLE
    New-TextToSpeechMessage -Message 'This is the text I want to have read out loud' -Voice Zira
#&gt;
    [CmdletBinding()]
    param(
        [Parameter(
            Position = 0,
            Mandatory = $true
        )]

        [string]    $Message,


        [Parameter(
            Position = 1,
            Mandatory = $false
        )]

        [ValidateSet('David', 'Zira')]
        [string]    $Voice = 'Zira'
    )

    BEGIN {
        if (-not ([appdomain]::currentdomain.GetAssemblies() | Where-Object {$_.Location -eq 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Speech\v4.0_4.0.0.0__31bf3856ad364e35\System.Speech.dll'})) {
            Add-Type -AssemblyName System.Speech
        }
    }

    PROCESS {
        try {
            $NewMessage = New-Object System.Speech.Synthesis.SpeechSynthesizer

            if ($Voice -eq 'Zira') {
                $NewMessage.SelectVoice(&quot;Microsoft Zira Desktop&quot;)
            } else {
                $NewMessage.SelectVoice(&quot;Microsoft David Desktop&quot;)
            }
    
            $NewMessage.Speak($Message)
    
        } catch {
            Write-Error $_.Exception.Message
        }        
    }

    END {}
}

</pre>
<p>So hopefully this article for going through the steps of using Powershell text to speech was able to help you out.  I know I don&#8217;t use it on a daily basis but it is something that can come in handy from time to time.  Not only that, it&#8217;s good to spruce up your Powershell skills so that&#8217;s another benefit to the script.</p>
<p>If you want to see more articles like this, be sure to check out our <a href="https://thesysadminchannel.com/powershell/" rel="noopener" target="_blank">Powershell Gallery</a> for other real world scripts.  Don&#8217;t forget to check our <a href="https://www.youtube.com/c/theSysadminChannel" rel="noopener" target="_blank">Youtube Channel</a> for other sysadmin video content.</p>
<p>The post <a href="https://thesysadminchannel.com/powershell-text-to-speech-how-to-guide/">Powershell Text To Speech | How To Guide</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/powershell-text-to-speech-how-to-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2154</post-id>	</item>
	</channel>
</rss>
