You are reading help file online using chmlib.com
|
This example builds a Visual Basic ActiveX DLL in order to demonstrate general object-oriented programming techniques, and more specifically, to demonstrate the use of the ISpeechRecoGrammar_CmdLoadFromResource method.
The DLL contains one resource, called "101," which is a compiled version of the Solitaire recognition grammar. This resource is used in the ISpeechRecoGrammar CmdLoadFromResource sample.
The DLL contains one method, called "SpeakToFile," which is used in the ISpeechPhraseAlternate code example.
Click Start, and then click Run. Paste this text into the text box:
"C:\Program Files\Microsoft Speech SDK 5.1\Bin\GC" C:\SOL.XML
If your Speech SDK is installed at a different location, adjust the path accordingly. Click OK, and the grammar compiler will compile SOL.XML into SOL.CFG
In Visual Basic, create an ActiveX DLL project.
An icon for the Resource Editor will appear on Visual Basic's standard toolbar.
On the File menu, click Make SpeechDocs.dll.
This is the text of the Solitaire grammar SOL.XML.
<GRAMMAR LANGID="409">
<DEFINE>
<ID NAME="FROM" VAL="1"/>
<ID NAME="TO" VAL="2"/>
<ID NAME="SUIT" VAL="3"/>
<ID NAME="COLOR" VAL="4"/>
<ID NAME="RANK" VAL="5"/>
<ID NAME="ColorRed" VAL="11101"/>
<ID NAME="ColorBlack" VAL="10011"/>
<ID NAME="RID_NewGame" VAL="101"/>
<ID NAME="RID_MoveCard" VAL="102"/>
<ID NAME="RID_Rank" VAL="103"/>
</DEFINE>
<RULE NAME="newgame" ID="RID_NewGame" TOPLEVEL="ACTIVE">
<P>new +game</P><O>-please</O>
</RULE>
<RULE NAME="playcard" TOPLEVEL="ACTIVE" EXPORT="1">
<O>please</O>
<P>play the</P>
<RULEREF NAME="card"/>
<O>please</O>
</RULE>
<RULE NAME="movecard" ID="RID_MoveCard" TOPLEVEL="ACTIVE">
<O>please</O>
<P>
<L>
<P>move</P>
<P>put</P>
</L>
<P>the</P>
</P>
<RULEREF PROPNAME="from" PROPID="FROM" NAME="card"/>
<O>
<L>
<P>on</P>
<P>to</P>
</L>
<P>the</P>
<RULEREF PROPNAME="to" PROPID="TO" NAME="card"/>
</O>
<O>please</O>
</RULE>
<RULE NAME="card">
<L>
<P>
<L PROPNAME="color" PROPID="COLOR">
<P VAL="ColorRed">red</P>
<P VAL="ColorBlack">black</P>
</L>
<RULEREF NAME="rank"/>
</P>
<P>
<RULEREF NAME="rank"/>
<O>
<P>of</P>
<L PROPNAME="suit" PROPID="SUIT">
<P VAL="0">clubs</P>
<P VAL="1">hearts</P>
<P VAL="2">diamonds</P>
<P VAL="3">spades</P>
</L>
</O>
</P>
<L PROPNAME="suit" PROPID="SUIT">
<P VAL="0">club</P>
<P VAL="1">heart</P>
<P VAL="2">diamond</P>
<P VAL="3">spade</P>
</L>
</L>
</RULE>
<RULE NAME="rank" ID="RID_Rank">
<L PROPNAME="rank" PROPID="RANK">
<P VAL="1">ace</P>
<P VAL="2">two</P>
<P VAL="3">three</P>
<P VAL="4">four</P>
<P VAL="5">five</P>
<P VAL="6">six</P>
<P VAL="7">seven</P>
<P VAL="8">eight</P>
<P VAL="9">nine</P>
<P VAL="10">ten</P>
<P VAL="11">jack</P>
<P VAL="12">queen</P>
<P VAL="13">king</P>
<P VAL="12">lady</P>
<P VAL="13">emperor</P>
</L>
</RULE>
</GRAMMAR>
This is the source code for SpeechDocs DLL.
Option Explicit
Private mV As SpeechLib.SpVoice
Private mF As SpeechLib.SpFileStream
Public Function SpeakToFile( _
ByVal strText, _
ByVal strFName, _
Optional NameOrToken _
) As SpFileStream
Set mV = New SpVoice 'Create voice object with default voice
If (Not IsMissing(NameOrToken)) Then
On Error GoTo BadNameOrToken
Select Case TypeName(NameOrToken) 'VBA.Information.TypeName
Case "String" 'Use string parameter as name of voice
Set mV.Voice = mV.GetVoices("name=" & NameOrToken).Item(0)
Case "ISpeechObjectToken" 'Use object token parameter as voice
Set mV.Voice = NameOrToken
End Select
End If
BadNameOrToken: 'Use default voice if Set from NameOrToken parameter fails
On Error GoTo OtherErrors
Set mF = New SpFileStream 'Create stream object
mF.Open strFName, SSFMCreateForWrite, True 'Open as the filename
Set mV.AudioOutputStream = mF 'Set voice output to file
mV.Speak strText, SVSFIsXML 'Speak synchronously
mF.Close 'Close file
OtherErrors: 'Exit on illegal file path or other err
Set mV = Nothing
Set SpeakToFile = mF 'Return Filestream object
End Function
You are reading help file online using chmlib.com
|