Premise [download] Driver: MS-SAPI Text-To-Speech

Motorola Premise

123

Senior Member
index.php
File Name: Driver: MS-SAPI Text-To-Speech
File Submitter: 123
File Submitted: 4 Mar 2009
File Category: Premise
Author: Rob Brun
Contact: Send PM to 123
Version: 1.0

MS SAPI 5.1 native driver for Premise. It allows you to easily make Premise talk, supports multiple sound cards and multiple voices. The attached zip file also includes installation instructions. Original author: Rob Brun.


Click here to download this file
 
The instructions are clear and simple, however it does not work. I am unable to select a voice or an output device and it does not find these item on the computer. Also I can't remove it from my computer. (Win 2000 Adv Server)
 
... it does not work. ... I can't remove it from my computer. (Win 2000 Adv Server) ...
The Speech driver uses Microsoft SAPI 5.1 to do its magic. SAPI 5.1 is included in Windows XP and Windows Server 2003. For Windows 2000, you can download it from here.

Microsoft provides a very useful tutorial for working with SAPI. You can use XML tags to specify how a phrase should be spoken. Here's a simple example:
<volume level="75"><emph>Attention!</emph><silence msec="750"/> The front door has been left open!".</volume>

Here's what the tags do in this phrase:
  1. Set volume to 75%
  2. Emphasize the word "Attention"
  3. Pause 3/4 seconds
  4. Speak the rest of the phrase using the default voice
  5. Set volume to its original level.

Here's how the script would look in Premise using the Speech driver:
Code:
sReminder = "<volume level=""75""><emph>Attention!</emph><silence msec=""750""/> The front door has been left open!".</volume>"
with Devices.MSSAPI.Speech
	.IsFile = false
	.IsXML = true
	.TTSData = sReminder
	.Speak = true
end with

Premise lets you use ActiveX objects in scripts, so you can forego using the Speech driver and control the SAPI ActiveX object directly. It is more work but useful on those rare occasions when you need additional control over speech. For example, the MSSAPI Speech driver is limited to rendering speech through the PC's audio cards so I used the SAPI ActiveX object to generate speech files that are "pushed" to a 3COM Audrey device.

Premise's use of VBScript is very handy because there are plenty of scripting examples available. Technet's Script Center offers many examples of scripting with ActiveX objects, WMI, etc. Here's a good article on SAPI.
 
... It works fine. ...
Glad to hear it!

You can manipulate the default Speech object's properties each time you use it (as seen in my previous post) or, better yet, create several, pre-configured Speech objects.

For example, create a new Speech object and call it "MaryXML". Set its properties as follows:
IsFile=false
IsXML=true
Voice=Microsoft Mary


Now your scripts can use MaryXML like this:
Code:
with Devices.MSSAPI.MaryXML
	.TTSData = "<emph>Hello world!</emph>"
	.Speak = true
end with
You can create several Speech objects to handle different TTS requirements:
  • SamFile
    Sam voice; content read from a file; sent to the default audio card.
  • MaryXMLSound2
    Mary voice; centent is a string with XML tags; sent to a second sound card.
  • MaryXMLFile
    Mary voice; content is in a file with XML tags; sent to the default audio card.
  • etc
 
I'm going to give this thing a try this weekend. However, I'm looking for ideas of what I should use it for? I don't have an intercom system, but I do have two sound cards installed. I was thinking about sending the speach to an external amplified speaker so if my system is off, I will still hear the voice.

Also, is there any way to get premise to work reliably with voice recognition? This could be useful for someone who has an intercome system; they could in theory press a button, say a command, and operate anything in their home! However, I haven't seen a module for voice recognition...

Some ideas I have so far:
Lighting/Home status when I press a predefined button. Perhaps when I hold any button on the X10 palm pad down for 2 seconds the system would give me status of things in the home...

Use a timer along with a subroutine that would give the new status (volume level or brightness) for whatever object's property I just changed. The timer is so that if I continually hit a button nothing is announced until .5 seconds after the last button press (I haven't implemented this idea or timers before, but I think it'd be easy to code).

A report will occur every night at 9PM stating the status of devices in the home.

I haven't done this one yet, but looking at 123's driver and dinki's ideas from another thread, this would be really useful for a home made security system.
 
This looks neat too, but without an intercom system and not owning my own home, I can't play with it too much. John and Rob sure made some neat modules from what I've read though! Makes me wonder what a real premise system can do compared to what a novice programmer like me can put together.

I've never tried it, and never got around to posting it in Premise Downloads, but have a look at the SpeechCommander module.
 
Anyone have this working with Vista? I can only get it to work on XP and I really need it to work on Vista B) I even tried a simple script like this:

strText = "Please wait while we connect to Active Directory"
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.Speak strText

Which works fine on XP, but not on Vista...? The line objVoice.Speak strText gives me an error that the property is not available. SAPI comes installed with Vista so I am confused.
 
I figured I'd try MS Access vbscript and see what it did. Voices work fine with vbscript on Vista!

I have no idea why Vista's SAPI (I think it's version 5.3 not 5.1) won't work through SYS on Vista though, and I really would like to get this to work as my HTPC must use Vista. I know the voice names are different and when I installed SAPI 5.1, it added some voices that would not work from the control panel. I'm considering moving my Premise install over to XP, but I have so many serial devices in my living room now I'd almost have to buy an 8 port Digi TS!

The other issue would be how to get the other soundcard signal to make it to my living room. I was thinking about using a USB soundcard plugged into a networked based USB portserver in the living.

Any ideas? I live in an apartment and can't run cables through the wall.

Anyone have this working with Vista? I can only get it to work on XP and I really need it to work on Vista :) I even tried a simple script like this:

strText = "Please wait while we connect to Active Directory"
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.Speak strText

Which works fine on XP, but not on Vista...? The line objVoice.Speak strText gives me an error that the property is not available. SAPI comes installed with Vista so I am confused.
 
FWIW, I couldn't get the MS-SAPI driver to work in Vista.

It's not the end of the world because VBScript let's you access COM objects like SAPI.spVoice. The following script lets you select a voice, specify the content type (words or a file containing the words) and plays the speech through the default audio card. See this MSDN page for a description of the AudioOutput property in order to specify the destination. I used something like this in my Audrey driver because I needed to direct the TTS output to a file and not an audio card .


Code:
' sVoice - string - voice name (i.e. "Microsoft Anna" or "Microsoft Mary")
' sContent - string - content to speak (Contains the words to speak or the name of a file containing the words).
' iContentType - integer - where:
'	0 is Text (Words to be spoken),
'	1 is a TextFile (File containing words),
'	2 is  XML (XML-encoded words),
'	3 is  XMLFile (File containing XML-encoded words).
dim oVoice, oVoices

set oVoice = CreateObject("SAPI.SpVoice")
set oVoices = oVoice.GetVoices("Name=" & sVoiceName)
if oVoices.Count > 0 then ' Found the desired voice
	set oVoice.Voice = oVoices.Item(0)
	oVoice.Speak sContent, iContentType
else ' Could not find the desired voice
	'  Handle the error
end if

set oVoice = nothing
set oVoices = nothing
 
Interesting. I'm running Vista 32 bit SP1 with minimal updates. If I remember right, you run Vista 64 bit? I'm still getting the error, but as before the exact same code works in Excel... Error is attached and code is below.
' sVoice - string - voice name (i.e. "Microsoft Anna" or "Microsoft Mary")
' sContent - string - content to speak (Contains the words to speak or the name of a file containing the words).
' iContentType - integer - where:
' 0 is Text (Words to be spoken),
' 1 is a TextFile (File containing words),
' 2 is XML (XML-encoded words),
' 3 is XMLFile (File containing XML-encoded words).
dim oVoice, oVoices
sVoiceName = "Microsoft Anna"
sContent = "Hello World"
iContentType = 0
set oVoice = CreateObject("SAPI.SpVoice")
set oVoices = oVoice.GetVoices("Name=" & sVoiceName)
if oVoices.Count > 0 then ' Found the desired voice
set oVoice.Voice = oVoices.Item(0)
oVoice.Speak sContent, iContentType
else ' Could not find the desired voice
' Handle the error
end if

set oVoice = nothing
set oVoices = nothing


FWIW, I couldn't get the MS-SAPI driver to work in Vista.

It's not the end of the world because VBScript let's you access COM objects like SAPI.spVoice. The following script lets you select a voice, specify the content type (words or a file containing the words) and plays the speech through the default audio card. See this MSDN page for a description of the AudioOutput property in order to specify the destination. I used something like this in my Audrey driver because I needed to direct the TTS output to a file and not an audio card .


Code:
' sVoice - string - voice name (i.e. "Microsoft Anna" or "Microsoft Mary")
' sContent - string - content to speak (Contains the words to speak or the name of a file containing the words).
' iContentType - integer - where:
'	0 is Text (Words to be spoken),
'	1 is a TextFile (File containing words),
'	2 is  XML (XML-encoded words),
'	3 is  XMLFile (File containing XML-encoded words).
dim oVoice, oVoices

set oVoice = CreateObject("SAPI.SpVoice")
set oVoices = oVoice.GetVoices("Name=" & sVoiceName)
if oVoices.Count > 0 then ' Found the desired voice
	set oVoice.Voice = oVoices.Item(0)
	oVoice.Speak sContent, iContentType
else ' Could not find the desired voice
	'  Handle the error
end if

set oVoice = nothing
set oVoices = nothing
 

Attachments

  • runtime_error.jpg
    runtime_error.jpg
    50.9 KB · Views: 31
I just tried the sample script on Vista and it doesn't work. It fails at the same place it did for you, namely when the script calls the Speak method. Very odd and probably the same thing that is happening to the MS-SAPI driver. It works everywhere else except when executed within Premise. The only thing I can think of is that there must be some sort of security in effect that prevents Premise from invoking the Speak method of the SAPI.spVoice object. This may take some time to solve ...
 
I haven't been able to find a fix for this problem. In a nutshell, something in Vista prevents Premise Server from executing SAPI's Speak method.

Up until Windows XP Service Pack 2 was introduced, System.CreateProcess would let Premise Server execute an external application. When Microsoft increased secruity in SP2, they effectively disabled a function call (CreateProcessWithLogonW) used by the "CreateProcess" method. Premise Server runs under the LocalSystem account and the new secruity measure prevents this account from invoking CreateProcessWithLogonW. I've tried running Premise Server using an alternate adminstrative account but this did not get around the obstacle. CreateProcess has been non-functional since SP2.

I suspect something like this may have happened in Vista. In Vista, an end-user, logged in with a user account, can call SAPI's Speak method from VBScript or Office's VBA. But Premise Server, running as LocalSystem, cannot. Well, that's my theory so far ...
 
Thanks for checking 123, I really appreciate it! What you are saying makes a lot of sense. From your findings, it sounds like if I put Premise on its own box, I want XP SP1 only for future use in case I need to use the CreateProcess method (I haven't needed to yet, but this is very useful information). I have a spare computer to do this with, but I'll have to wait until I have more time to reload XP SP1 onto it.

As a side note: what is interesting is SAPI works on my X64 XP SP2 computer.

I haven't been able to find a fix for this problem. In a nutshell, something in Vista prevents Premise Server from executing SAPI's Speak method.

Up until Windows XP Service Pack 2 was introduced, System.CreateProcess would let Premise Server execute an external application. When Microsoft increased secruity in SP2, they effectively disabled a function call (CreateProcessWithLogonW) used by the "CreateProcess" method. Premise Server runs under the LocalSystem account and the new secruity measure prevents this account from invoking CreateProcessWithLogonW. I've tried running Premise Server using an alternate adminstrative account but this did not get around the obstacle. CreateProcess has been non-functional since SP2.

I suspect something like this may have happened in Vista. In Vista, an end-user, logged in with a user account, can call SAPI's Speak method from VBScript or Office's VBA. But Premise Server, running as LocalSystem, cannot. Well, that's my theory so far ...
 

Similar threads

C
Replies
0
Views
785
chucklyons
C
C
Replies
0
Views
1K
chucklyons
C
Replies
16
Views
3K
chucklyons
C
C
Replies
2
Views
1K
chucklyons
C
C
Replies
2
Views
1K
Back
Top