Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

SAPI 5.1: Voice - Enabled Applications

Discussion in 'Information Technology' started by PC User, Nov 4, 2005.

  1. PC User

    PC User
    Expand Collapse
    Guest

    I'm trying to apply some code that I've found on Text Reading and
    Speech Recongnition. I don't know what version of VB that it was
    develop. I've posted my project that I'm working on and I was hoping
    someone could help me get it to work. It can be found at:
    http://www.access-programmers.co.uk/forums/attachment.php?attachmentid=11527

    The code is from:
    SAPI 5.1: Voice - Enabled Applications With VB
    By Peter A. Bromberg, Ph.D.
    http://www.eggheadcafe.com/articles/20011124.asp

    Thanks for your time.
    PC
     
  2. Loading...


  3. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    I'm not about to download and open the attachment, but the code outlined in
    the eggheadcafe article worked fine for me in Access 97, so I'd assume it'll
    work in newer versions as well.

    What problem are you having?

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "PC User" <pc_user@SoftHome.net> wrote in message
    news:1131069553.938580.188580@g44g2000cwa.googlegroups.com...
    > I'm trying to apply some code that I've found on Text Reading and
    > Speech Recongnition. I don't know what version of VB that it was
    > develop. I've posted my project that I'm working on and I was hoping
    > someone could help me get it to work. It can be found at:
    >

    http://www.access-programmers.co.uk/forums/attachment.php?attachmentid=11527
    >
    > The code is from:
    > SAPI 5.1: Voice - Enabled Applications With VB
    > By Peter A. Bromberg, Ph.D.
    > http://www.eggheadcafe.com/articles/20011124.asp
    >
    > Thanks for your time.
    > PC
    >
     
  4. Tom Wickerath

    Tom Wickerath
    Expand Collapse
    Guest

    Hi Doug,

    I downloaded PC User's sample last night and tried it in Access 2002. I
    could not get it to work properly. I found something really strange. I could
    get the btnReadToMe_Click() and btnSpeakToMe_Click() procedures to work, in
    Access, only in break mode (ie. setting a break point and then executing each
    line with the F8 key). When I removed the break point, I didn't hear anything:

    Private Sub btnReadToMe_Click()
    Dim Voice As SpVoice
    Set Voice = New SpVoice
    Voice.Speak Nz(Me.Text0, ""), SVSFlagsAsync
    End Sub

    Private Sub btnSpeakToMe_Click()
    Dim Voice As SpVoice
    Set Voice = New SpVoice
    Voice.Speak "Hello. My name is Peter.", SVSFlagsAsync
    End Sub

    I converted the sample to Access 97. The same thing is happening....no voice
    heard unless I run the code in break mode. In addition, I received an
    ambiguous name detected error in Access 97 when I attempted to compile the
    code. This occurred on the line of code that reads:

    Dim WithEvents RecoContext As SpSharedRecoContext

    which was found in two Private Subs. I commented out these two declarations
    and moved this line of code to the top of the module, to declare this at the
    module level. When I attempt to compile in Access 97, I'm now receiving
    "Automation type not supported in Visual Basic" error on the following:

    ' the following is the event handler for the recognition event
    Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, _
    ByVal StreamPosition As Variant, _
    ByVal RecognitionType As SpeechRecognitionType, _
    ByVal Result As ISpeechRecoResult _
    )


    In short, I'm not having much luck getting this to work in either Access 97
    or 2002. I thought last night that perhaps this code only works in VB, not
    VBA, but your mention that you can get it to work in Access 97 seems to
    indicate that something else is the problem.

    Is there any chance that you would be willing to post your working sample in
    Access 97 to your web site?

    Thanks,

    Tom
    ______________________________________________

    "Douglas J Steele" wrote:

    I'm not about to download and open the attachment, but the code outlined in
    the eggheadcafe article worked fine for me in Access 97, so I'd assume it'll
    work in newer versions as well.

    What problem are you having?

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)
     
  5. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    Actually, I noticed that too, so I removed the svsFlagsAsync parameter from
    the invocation of the Voice.Speak method.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Tom Wickerath" <AOS168 AT @comcast DOT net> wrote in message
    news:D6BD4FF9-D90F-4660-AF69-3E4772137691@microsoft.com...
    > Hi Doug,
    >
    > I downloaded PC User's sample last night and tried it in Access 2002. I
    > could not get it to work properly. I found something really strange. I

    could
    > get the btnReadToMe_Click() and btnSpeakToMe_Click() procedures to work,

    in
    > Access, only in break mode (ie. setting a break point and then executing

    each
    > line with the F8 key). When I removed the break point, I didn't hear

    anything:
    >
    > Private Sub btnReadToMe_Click()
    > Dim Voice As SpVoice
    > Set Voice = New SpVoice
    > Voice.Speak Nz(Me.Text0, ""), SVSFlagsAsync
    > End Sub
    >
    > Private Sub btnSpeakToMe_Click()
    > Dim Voice As SpVoice
    > Set Voice = New SpVoice
    > Voice.Speak "Hello. My name is Peter.", SVSFlagsAsync
    > End Sub
    >
    > I converted the sample to Access 97. The same thing is happening....no

    voice
    > heard unless I run the code in break mode. In addition, I received an
    > ambiguous name detected error in Access 97 when I attempted to compile the
    > code. This occurred on the line of code that reads:
    >
    > Dim WithEvents RecoContext As SpSharedRecoContext
    >
    > which was found in two Private Subs. I commented out these two

    declarations
    > and moved this line of code to the top of the module, to declare this at

    the
    > module level. When I attempt to compile in Access 97, I'm now receiving
    > "Automation type not supported in Visual Basic" error on the following:
    >
    > ' the following is the event handler for the recognition event
    > Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, _
    > ByVal StreamPosition As Variant, _
    > ByVal RecognitionType As SpeechRecognitionType, _
    > ByVal Result As ISpeechRecoResult _
    > )
    >
    >
    > In short, I'm not having much luck getting this to work in either Access

    97
    > or 2002. I thought last night that perhaps this code only works in VB, not
    > VBA, but your mention that you can get it to work in Access 97 seems to
    > indicate that something else is the problem.
    >
    > Is there any chance that you would be willing to post your working sample

    in
    > Access 97 to your web site?
    >
    > Thanks,
    >
    > Tom
    > ______________________________________________
    >
    > "Douglas J Steele" wrote:
    >
    > I'm not about to download and open the attachment, but the code outlined

    in
    > the eggheadcafe article worked fine for me in Access 97, so I'd assume

    it'll
    > work in newer versions as well.
    >
    > What problem are you having?
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
     
  6. Tom Wickerath

    Tom Wickerath
    Expand Collapse
    Guest

    Thanks Doug,

    I'm now successful in getting two of the three command buttons on PC User's
    sample to function correctly: the buttons labelled "Read" and "RD". These
    buttons have the following two click event procedures, respectively:

    Private Sub btnReadToMe_Click()
    Dim Voice As SpVoice
    Set Voice = New SpVoice
    Voice.Speak Nz(Me.Text0, "")
    End Sub

    Private Sub btnSpeakToMe_Click()
    Dim Voice As SpVoice
    Set Voice = New SpVoice
    Voice.Speak "Hello. My name is Peter."
    End Sub

    I haven't gotten his button labelled "WT" to function. The click event for
    this button is apparently intended to write something to a file. However,
    this is a great start.

    Thank You,

    Tom
    ____________________________________________

    "Douglas J Steele" wrote:

    Actually, I noticed that too, so I removed the svsFlagsAsync parameter from
    the invocation of the Voice.Speak method.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)
     
  7. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    Now that I'm home, I'll grab it and take a look.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)



    "Tom Wickerath" <AOS168 AT @comcast DOT net> wrote in message
    news:954C887A-BE77-495C-B1B2-FFAF22AE6503@microsoft.com...
    > Thanks Doug,
    >
    > I'm now successful in getting two of the three command buttons on PC
    > User's
    > sample to function correctly: the buttons labelled "Read" and "RD". These
    > buttons have the following two click event procedures, respectively:
    >
    > Private Sub btnReadToMe_Click()
    > Dim Voice As SpVoice
    > Set Voice = New SpVoice
    > Voice.Speak Nz(Me.Text0, "")
    > End Sub
    >
    > Private Sub btnSpeakToMe_Click()
    > Dim Voice As SpVoice
    > Set Voice = New SpVoice
    > Voice.Speak "Hello. My name is Peter."
    > End Sub
    >
    > I haven't gotten his button labelled "WT" to function. The click event for
    > this button is apparently intended to write something to a file. However,
    > this is a great start.
    >
    > Thank You,
    >
    > Tom
    > ____________________________________________
    >
    > "Douglas J Steele" wrote:
    >
    > Actually, I noticed that too, so I removed the svsFlagsAsync parameter
    > from
    > the invocation of the Voice.Speak method.
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
     
  8. PC User

    PC User
    Expand Collapse
    Guest

    Thank you for your discussion on my project. I made the demo that you
    downloaded based on interpretation of the article by Dr. Bromberg. I
    may not have explained the buttons adequately. The Read button is
    "Read To Me" from what is typed in the textbox. The RD button is
    "Speak To Me" from the text in the onClick event of the RD button.
    The WT button is "Write My Speech" for speech recognition to type
    in your spoken word into the textbox when you have a microphone
    attached to the computer. This is Dr. Bromber's code to convert the
    spoken word into written text.
    All the issues that Tom brought up are the ones that I experienced and
    the questions that he has asked are the ones that I would have asked
    also. It looks as though we are making progress on this.
     
  9. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    Afraid I don't have a microphone handy, so I can't do much with the
    speech-to-text functionality.

    In the routine InitializeGrammar, reference is made to App.Path &
    "\newnums.xml". This is supposed to be the XML file mentioned in the
    article. You'll need to replace App.Path with a reference to the path to
    where the file is. If want to point to the same folder where the MDB file
    is, and you're using Access 2000 or newer, you can use
    Application.CurrentProject.Path & "\". (If you're using Access 97, you can
    use Left$(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir$(CurrentDb.Name))))

    In addition to moving the line Dim WithEvents RecoContext As
    SpSharedRecoContext to the top of the module (so that it applies to all
    modules), I believe it's also necessary to move Dim Grammar As
    ISpeechRecoGrammar

    It looks as though there might be no way around the "Automation type not
    supported" message in Access 97 for the RecoContext_Recognition sub. That
    error doesn't occur in Access 2003, though, so if you're using Access 2000
    or newer, I think you might be okay.

    If I can steal my daughter's microphone sometime this weekend, I'll see
    whether I can get any further.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)



    "PC User" <pc_user@SoftHome.net> wrote in message
    news:1131159699.461879.79380@o13g2000cwo.googlegroups.com...
    > Thank you for your discussion on my project. I made the demo that you
    > downloaded based on interpretation of the article by Dr. Bromberg. I
    > may not have explained the buttons adequately. The Read button is
    > "Read To Me" from what is typed in the textbox. The RD button is
    > "Speak To Me" from the text in the onClick event of the RD button.
    > The WT button is "Write My Speech" for speech recognition to type
    > in your spoken word into the textbox when you have a microphone
    > attached to the computer. This is Dr. Bromber's code to convert the
    > spoken word into written text.
    > All the issues that Tom brought up are the ones that I experienced and
    > the questions that he has asked are the ones that I would have asked
    > also. It looks as though we are making progress on this.
    >
     
  10. PC User

    PC User
    Expand Collapse
    Guest

  11. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    To determine what voices have been defined, you can use the following code:

    Dim objVoice As SpeechLib.SpVoice
    Dim objToken As SpeechLib.ISpeechObjectToken

    Set objVoice = New SpVoice

    ' Get each token in the collection returned by GetVoices

    For Each objToken In objVoice.GetVoices
    Debug.Print objToken.GetDescription
    Next objToken

    Once you know which voice you want (the number of the voice, not the name),
    you can use

    Dim objVoice As SpeechLib.SpVoice

    Set objVoice = New SpVoice
    Set objVoice.Voice = objVoice.GetVoices().Item(intLoop)
    objVoice.Speak "Hello, Doug"


    Here's some code I wrote to speek the same phrase in all of the voices
    available on the machine:

    Sub IdentifyTheVoices()

    Dim objVoice As SpeechLib.SpVoice
    Dim objToken As SpeechLib.ISpeechObjectToken
    Dim intLoop As Integer
    Dim strVoice As String
    Dim varVoices As Variant

    Set objVoice = New SpVoice

    ' Get each token in the collection returned by GetVoices
    ' and concatentate its description into a string variable

    For Each objToken In objVoice.GetVoices
    strVoice = strVoice & objToken.GetDescription & ";"
    Next

    If Len(strVoice) > 0 Then

    ' Remove the extraneous semi-colon from the end
    strVoice = Left$(strVoice, Len(strVoice) - 1)

    ' Split the concatenated string into an array of voice names.
    varVoices = Split(strVoice, ";")

    ' Check that we actually have an array of voice descriptions
    If IsNull(varVoices) = False Then

    ' Loop through the array of voice descriptions, speaking
    ' a phrase using each voice.

    For intLoop = LBound(varVoices) To UBound(varVoices)
    Set objVoice.Voice = objVoice.GetVoices().Item(intLoop)
    objVoice.Speak "I'm currently speaking using voice " &
    varVoices(intLoop)
    Next intLoop

    End If

    End If

    End Sub


    Sorry: I didn't have a chance to look at speech to text over the weekend.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "PC User" <pc_user@SoftHome.net> wrote in message
    news:1131232358.339232.75590@f14g2000cwb.googlegroups.com...
    > I've made some progress, but I still need help. I'm trying to make the
    > voices change and I'm also trying to get it to recognize my speech
    > through a microphone. My current file is posted at:
    >

    http://www.access-programmers.co.uk/forums/attachment.php?attachmentid=11551
    > and I'm using the documentation from:
    >

    http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/sapi.chm
    >
    > Thanks,
    > PC
    >
     
  12. PC User

    PC User
    Expand Collapse
    Guest

    Thanks much Doug. I've been applying the examples given in the
    documentation. I'm getting a little further along on this, but I'm
    having trouble with the volume control and the speed rate. Also I can't
    get the write to file or read from file to work, probably because the
    original code is in a different version of visual basic. I'm thinking
    that I should use the Common Dialog ActiveX for the read/write actions.
    Any help on this is appreciated. The current file is located at:
    http://www.access-programmers.co.uk/forums/attachment.php?attachmentid=11559
     
  13. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    Volume is a numeric value between 0 and 100:

    Set objVoice = New SpVoice

    objVoice.Volume = 75
    objVoice.Speak "How do you do?"

    There is no "Speed" property, but there is a Rate property. It's a numeric
    property between -10 and 10:

    Set objVoice = New SpVoice

    For intLoop = -10 To 10 Step 2
    objVoice.Rate = intLoop
    objVoice.Speak "I'm speaking using rate " & intLoop
    Next intLoop


    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "PC User" <pc_user@SoftHome.net> wrote in message
    news:1131389135.902768.198520@g47g2000cwa.googlegroups.com...
    > Thanks much Doug. I've been applying the examples given in the
    > documentation. I'm getting a little further along on this, but I'm
    > having trouble with the volume control and the speed rate. Also I can't
    > get the write to file or read from file to work, probably because the
    > original code is in a different version of visual basic. I'm thinking
    > that I should use the Common Dialog ActiveX for the read/write actions.
    > Any help on this is appreciated. The current file is located at:
    >

    http://www.access-programmers.co.uk/forums/attachment.php?attachmentid=11559
    >
     
  14. PC User

    PC User
    Expand Collapse
    Guest

    Doug,

    I get an "Error# -214720096: Automation error" when I try the
    speech recognition, even with my microphone connected. Do you have any
    idea what that means?

    Thanks,
    PC
     
  15. Tom Wickerath

    Tom Wickerath
    Expand Collapse
    Guest

    Hi PC,

    I've still been following this thread, because I have some interest in this
    SAPI functionality. Thanks for posting your latest sample too.

    Here is a KB article that you might find helpful:

    INFO: Translating Automation Errors for VB/VBA (Long)
    http://support.microsoft.com/?id=186063


    You can copy the first block of code shown, under "Use FormatMessage", and
    paste it into a new module in Access. Change the Private Function to a Public
    Function, so that you can call it from the Immediate window:

    Change this:
    Private Function MessageText(lCode As Long) As String

    to this:
    Public Function MessageText(lCode As Long) As String

    However, when I do this, and then call the function from the immediate
    window, I get the following result:

    ?messagetext(214720096)
    Error not found.

    Can you verify that you reported the correct error number?

    Thanks,
    Tom

    ________________________________________________

    "PC User" wrote:

    Doug,

    I get an "Error# -214720096: Automation error" when I try the
    speech recognition, even with my microphone connected. Do you have any
    idea what that means?

    Thanks,
    PC
     
  16. Tom Wickerath

    Tom Wickerath
    Expand Collapse
    Guest

    PS. Including the minus sign yields the same message:

    ?MessageText(-214720096)
    Error not found.

    ________________________________________________

    "Tom Wickerath" wrote:

    Hi PC,

    I've still been following this thread, because I have some interest in this
    SAPI functionality. Thanks for posting your latest sample too.

    Here is a KB article that you might find helpful:

    INFO: Translating Automation Errors for VB/VBA (Long)
    http://support.microsoft.com/?id=186063


    You can copy the first block of code shown, under "Use FormatMessage", and
    paste it into a new module in Access. Change the Private Function to a Public
    Function, so that you can call it from the Immediate window:

    Change this:
    Private Function MessageText(lCode As Long) As String

    to this:
    Public Function MessageText(lCode As Long) As String

    However, when I do this, and then call the function from the immediate
    window, I get the following result:

    ?messagetext(214720096)
    Error not found.

    Can you verify that you reported the correct error number?

    Thanks,
    Tom

    ________________________________________________

    "PC User" wrote:

    Doug,

    I get an "Error# -214720096: Automation error" when I try the
    speech recognition, even with my microphone connected. Do you have any
    idea what that means?

    Thanks,
    PC
     
  17. PC User

    PC User
    Expand Collapse
    Guest

    Hi Tom,

    It seems that I've gotten almost everything working, but the
    speech recognition and the read/write functions. When I try the speech
    recognition, I get the "Error# -214720096: Automation error". I tried
    it several times and it seems unusual to get a negative error number.
    I'm thinking it might have something with the network security at the
    company where I work, but I'm not sure. Have you tried the read/write
    function? The documentation file has some sample code that I'm trying.
    Have you see it?

    PC
     
  18. Tom Wickerath

    Tom Wickerath
    Expand Collapse
    Guest

    Hi PC,

    > ...it seems unusual to get a negative error number.

    It isn't unusual at all for the automation errors to be negative; in fact
    most of them are negative. Scroll down the page of the KB article that I
    provided a link to:

    INFO: Translating Automation Errors for VB/VBA (Long)
    http://support.microsoft.com/?id=186063

    You should see lots of negative error numbers.

    > Have you tried the read/write function?

    No, not yet. I also do not have a microphone currently connected to my PC,
    so I cannot test out any speech recognition functionality.

    > The documentation file has some sample code that I'm trying.
    > Have you see it?


    Yes, I downloaded the compiled help file Sapi.chm (thanks for that link
    too), but I can't say that I've put any significant time into reading it at
    this point.

    Tom
    _________________________________________

    "PC User" wrote:

    Hi Tom,

    It seems that I've gotten almost everything working, but the
    speech recognition and the read/write functions. When I try the speech
    recognition, I get the "Error# -214720096: Automation error". I tried
    it several times and it seems unusual to get a negative error number.
    I'm thinking it might have something with the network security at the
    company where I work, but I'm not sure. Have you tried the read/write
    function? The documentation file has some sample code that I'm trying.
    Have you see it?

    PC
     
  19. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    Unfortunately, I only have Access 97 installed (plus no mike) here, and as
    discussed previously, the code won't work in Access97 for speech
    recognition: there's an Automation error message when you compile the code.

    What line of code is causing the error?

    Have you downloaded the entire SAPI SDK? When you install it, there are a
    number of VB samples that install, including one called VB SimpleDict. Does
    it work for you? (the code behind that app is essentially identical to
    what's in the Egghead article)

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "PC User" <pc_user@SoftHome.net> wrote in message
    news:1131463469.549942.256260@g49g2000cwa.googlegroups.com...
    > Doug,
    >
    > I get an "Error# -214720096: Automation error" when I try the
    > speech recognition, even with my microphone connected. Do you have any
    > idea what that means?
    >
    > Thanks,
    > PC
    >
     
  20. PC User

    PC User
    Expand Collapse
    Guest

    In the btnWriteMySpeech command button's onclick event the line: "Set
    RecoContext = New SpSharedRecoContext" creates the error "Error#
    -214720096: Automation error". I don't know whether the subsequent
    lines are good, because I haven't gotten past the first error. Also I
    don't see any calls for the Initialize() function; so I don't know
    where it should be called from.
    Later today, I'll check out the "VB SimpleDict" to see if it works for
    A2K.

    Thanks,
    PC
     
  21. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    I finally got around to testing in Access 2003 (in Access 2000 format) using
    a mike, and speech recognition worked fine for me.

    Not sure what advice I can give you: I didn't need to make any changes to
    the code at all.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)



    "PC User" <pc_user@SoftHome.net> wrote in message
    news:1131481679.496227.280090@o13g2000cwo.googlegroups.com...
    > In the btnWriteMySpeech command button's onclick event the line: "Set
    > RecoContext = New SpSharedRecoContext" creates the error "Error#
    > -214720096: Automation error". I don't know whether the subsequent
    > lines are good, because I haven't gotten past the first error. Also I
    > don't see any calls for the Initialize() function; so I don't know
    > where it should be called from.
    > Later today, I'll check out the "VB SimpleDict" to see if it works for
    > A2K.
    >
    > Thanks,
    > PC
    >
     

Share This Page