Sunday, December 21, 2014

PowerShell Text-to-Speech (TTS).

Here is a PowerShell one liner for Text-to-Speech (TTS) using Microsoft's desktop oriented Speech API (SAPI).

(New-Object -ComObject Sapi.SpVoice).Speak("Hello There!")

It uses New-Object to create a Component Object Model (COM) instance of SAPI spVoice.

Actually, if you plan to use speech in script it will make more sense to keep the object around for reuse.

$synth = New-Object -ComObject Sapi.SpVoice
$synth.Speak("Hello Again!")

In the Windows jungle there is no escape from King-COM!


Oh...wait..You can also access SAPI via .NET instead of directly using COM.  You can make the SAPI  System.speech assembly accessible by using Add-Type.

Add-Type -AssemblyName System.speech
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$synth.Speak("Hello from dot net")

SAPI is fun to play with but it comes with a limited set of voices and speech recognizers.  If you want to experiment with other voices you'll need to purchase them or switch speech systems.  One option is the Microsoft Speech Platform which supports several additional voices.

Unfortunately, voices and speech recognizers are not compatible between the two Microsoft speech systems. They have slightly different designs reflecting their different use cases.  SAPI is designed for desktop platforms and single users.  The SAPI speech recognizers are tuneable to a specific user and they support recognition of arbitrary words with a diction engine.  A single  running instance of the SAPI speech system can be shared among many applications (i.e. the SAPI provider runs out-of-process).  The Speech Platform is server oriented.  It is in-process (AKA InProc) so each process that requires speech capabilities will have it's own instance of the Speech Platform speech system.  You could run multiple speech capable processes on a single server (e.g. concurrent voice recognition processes on several users voice mailboxes).

I'm assuming that you have already downloaded and installed the Microsoft Speech Platform SDK, runtime, language packs (speech recognizers and text-to-speech voices) you want to use.  Once again, use Add-Type to add the Speech Platform assembly and create Microsoft.Speech objects in a PowerShell environment.  The Speech Platform requires you to set the audio output destination so you can hear what is said.

Add-Type -Path "C:\Program Files\Microsoft SDKs\Speech\v11.0\Assembly\Microsoft.Speech.dll"
$ms_speak = New-Object Microsoft.Speech.Synthesis.SpeechSynthesizer
$ms_speak.setOutputToDefaultAudioDevice()
$ms_speak.Speak("Hello, again, and again!")

After creating the SpeechSynthesizer object You can record the speech to a file with:

$ms_speak.setOutputToWaveFile("hello.wav")
$ms_speak.Speak("Greetings")
$ms_speak.Dispose()

You must Dispose of the object to commit the speech audio data to the named file.

I recommend  reviewing the MSDN documentation for both speech systems. Also, check out the Out-Voice function and this blog post (both by Boe Prox) he describes how you can spelunk the two systems from PowerShell with Get-Member.  Finally, Language Packs provide SAPI text-to-speech voices and speech recognizers for a few non-English languages.
--
P.S. Technically you can use SAPI InProc or shared (out-of-process).
P.P.S. There really is no getting away from COM.  It's still one of the architectural pillars of Microsoft server and desktop products.



Sunday, November 16, 2014

PowerShell one liner to download a file from a URL

PowerShell 3 and 4 include the Invoke-WebRequest (wget) to download a file from a URL.

A PowerShell 4 one liner to download a file from a URL is:

Invoke-WebRequest url -OutFile filename

Replace url with a string that has the full URL for the file and replace filename with a string containing the local file name.  For example, to download get-pip.py I could do the following:

Invoke-WebRequest "https://raw.github.com/pypa/pip/master/contrib/get-pip.py" -OutFile "get-pip.py"

 In PowerShell 2 you can use the following one liner to achieve the same.

(New-Object System.Net.WebClient).DownloadFile(url,filename)

For example, to download get-pip.py I could do the following:

(New-Object System.Net.WebClient).DownloadFile("https://raw.github.com/pypa/pip/master/contrib/get-pip.py","get-pip.py")

Optionally, if you are running Windows 7 you could switch  to PowerShell 4 by installing Windows Management Framework 4.0.


Sunday, August 31, 2014

Install Kinect for Windows SDK v1.8

Here are the steps I completed to install the Kinect for Windows SDK version 1.8 on a Windows 8.1 x64 box with Visual Studio 2010 already installed.  These steps were adapted from the Kinect for Windows SDK 1.8 System Requirements page at MSDN.

1. Uninstall Microsoft Visual C++ 2010 x86 & x64 Redistributable.  KB2728613 provides the following:
MsiExec.exe /passive /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}

MsiExec.exe /passive /X{1D8E6291-B0D5-35EC-8441-6616F567A0F7}
2. Install the DirectX Software Development Kit. At the moment this seems to be the June 2010 version.

3. Update Microsoft Visual C++ 2010 x86 & x64 Redistributable.  I used Windows Update.


5. Install Games for Windows Marketplace Client.  See Stack Overflow "How to install the XNA Game Studio 4.0 in Windows 8?" for the reason why. Install Microsoft XNA Game Studio 4.0.  (It might be worth checking one of the versions at XNA Game Studio project on Codeplex.

6. Finally, Install KinectSDK v1.8 and Kinect for Windows Developer Toolkit v1.8.

Saturday, August 30, 2014

Silent Uninstall of All Java on a Windows Box



Finally figured out a command line method to do a silent uninstall of all Java on a Windows box.  Open a command window as Administrator, then run the following wmic:

wmic product where "name like 'Java %% %%'" call uninstall /nointeractive
That is so much easier than manually uninstalling.

Tuesday, July 1, 2014

Fix Windows 8.1 mouse pointer stutter in Ace of Spades

I started having mouse problems after upgrading to Windows 8.1 when playing Ace of Spades.  I was almost convinced that it was a hardware problem.

Turns out that Microsoft changed the mouse polling for 8.1.  Microsoft has a patch for this at KB2908279.  I downloaded and ran the "Microsoft Fix it" on Ace of Spaces.  After running, I had to reboot.  After rebooting I ran the game with no change...still lots of mouse stutter.

The KB2908279 fix it recommended checking KB2907018 and KB2907016. KB2907016 is the "Disable display scaling on high DPI settings" and it did the trick for my hardware/software setup.

Thursday, February 13, 2014

Windows Search iFilter for PDF files.

I'm working on some papers for an online class and found out that Windows search doesn't have a built in iFilter for PDF files.  Since I'm using a 64-bit Windows 7 box I downloaded the Adobe PDF iFilter 64 11.0.01; installed; and Windows is now indexing.

Saturday, January 4, 2014

Empire Earth 2 window mode

I picked up Empire Earth 2 from gog.com but was having some issues with multiple-monitors.  After a bit of googling I came across a solution from someone going by galatei at neoseeker.  Add the following lines to the config.cfg (or config_EE2X.cfg for EE2:TAS):

g_bFullscreen = 0 
g_allowWindowedMode = 1 
g_ConstrainCursor = 0 
s_windowXOffset = 10 
s_windowYOffset = 10 
s_adapterIndex = 0

Worked for me in single player mode.