| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
|
If you use a lot of Windows Scripting (WSH), then you might find this useful - using SAPI's Text-to-speech (TTS) engine within WSH files is very easy. Here is the function:
// Speak the given phrase, returns when speaking finishes
function wshSpeak(phrase) {
var vt = WScript.CreateObject("Speech.VoiceText");
vt.Register("", WScript.ScriptName);
vt.Speak(phrase, 1);
while ( vt.IsSpeaking ) WScript.Sleep(100);
}
This requires the vtxtauto.tlb (normally found in c:\windows\speech), if don't have it you can download the Speech SDK from Microsoft (a pretty hefty download if you only want this TTS ability, though).
Reusing the CodeIf you put the code into a separate file (let's say "wshTTS.js"), you can use it in a Windows Script File (WSF) over again and across languages too. For example:
<job>
<script language="JScript" src="wshTTS.js" />
<script language="VBScript">
wshSpeak "This is Sapi talking from a WSF file"
</script>
</job>
MSAgent and TTSAs much as I dislike MSAgent, here is some code that demonstrates how to control Microsoft Agent and its TTS features:
Dim AgentControl
On Error Resume Next
Set AgentControl = CreateObject("Agent.Control.1")
If IsObject(AgentControl) Then
AgentControl.Connected = True
Dim genie
On Error Resume Next
' You might need to change this line to suit your system
' The Agent name and directory may change.
AgentControl.Characters.Load "genie", "C:\WINDOWS\Msagent\CHARS\GENIE.ACS"
Set genie = AgentControl.Characters ("genie")
genie.Get "state", "Showing"
genie.Get "state", "Speaking"
genie.MoveTo 20, 20
genie.Show
genie.Get "state", "Moving"
genie.MoveTo 200, 200
genie.Speak ("Hello!! I'm an annoying darkblue genie!")
WScript.Sleep(1000)
genie.Speak ("Bye!")
genie.Hide
End If
Wscript.echo "Note: MSAgent stuff executes in a separate thread."
ConclusionAs you can see Windows Scripting makes it very easy to add TTS abilities to scripts, HTML Applications, and a variety of other related technologies.
Submitted: 15/07/2001 Article content copyright © James Matthews, 2001.
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -