Monday, January 6, 2014

SpeechSynthesizer throws exception in windows 8.1 computer and RT 8.1 device

In my development lab, I have 2 windows 8.1 computers and one first generation Surface device. One of the Windows 8.1 box was a fresh windows 8.1 installation, another one was upgraded from Window 8.0 to Window 8.1.
I use them for mt TTS app development Well, a few days ago, I got a new Surface 2 device. I was so excited about it. I wasted no time before loading my TTS app to it. To my surprise, as soon as the code is supposed to talk,  the app crashes. I feel I have the obligation to figure what is going on and how to bring fix it in Surface 2 before me submitting the app to Microsoft app store. My first action was going back to the Speech synthesis sample provided as part of SDK library and run the sample app. I got the same behavior I filed a support ticket with Microsoft, have been working with Microsoft support professional for about a week. During the time, the same behavior starts to show up in my fresh window 8.1 box.  After many late nights and a chain of emails back and forth, the root cause is identified and walk around is proven working. This turns out to be a bug in Microsoft 8.1 in both RT and Windows OS. The bug only shows up in fresh installed 8.1.

As soon as this line is executed:

synthesisStream = await this.synthesizer.SynthesizeSsmlToStreamAsync(MyTextToBeRead.Text);  

An exception is thrown
               A first chance exception of type
'System.UnauthorizedAccessException' occurred in mscorlib.dll

WinRT information: Access is denied.

The root of the issue seems to be with the permissions on CurrentUserLexicon key under HKEY_CURRENT_USER\Software\Microsoft\Speech. If you run following powershell command on the problem box, you will get the result shown on the screenshot:
Get-Acl -Path HKCU:"Software\Microsoft\Speech\CurrentUserLexicon" |Format-List

The problem is with the extra entry of “ALL APPLICATION PACKAGES”. This extra entry only exists in fresh installed Window 8.1. All it takes is remove this permission entry from Software\Microsoft\Speech\CurrentUserLexicon
After remove the permission entry from the registry key, Under Regedit you will get following screenshot:

Under window powershell, you will get screen shot similar to the following:

Once that is done, your SpeechSynthesizer will start talking.

If you upgrade from Windows 8.0 to Windows 8.1 you are fine. That explains why it works in Microsoft Surface but not in Surface 2, because Surface 2 is a fresh installed Window RT 8.1, while in Surface case, it is upgraded from Windows RT 8.0 to Window RT 8.1.


  1. Forgive me, but how does this walkaround help the users of my app?

    1. this work around will eliminate the exception. so your users will be able to use your app without problem.