Sapi5

LostAngel
12-31-2007, 09:34 AM
Hello, below is a test program written by VB:

'===================================================================== ========
' This sample demonstrates how to do simple dictation in VB with SAPI 5.1.
'
' It uses shared reco context object, uses the default audio input, loads in
' dictation grammar, sets up event handlers, and shows the recognized text in
' the dialog text box.
'
' Note: since the text box is using system locale, it may not correctly show
' characters in other languages. For example, if you use Chinese Speech
' Recognition engine as the default engine on your English OS, the text box
' may show garbage even though the engine recognizes Chinese.
'
' Copyright @ 2001 Microsoft Corporation All Rights Reserved.
'
'===================================================================== ========

Option Explicit

Dim WithEvents RecoContext As SpSharedRecoContext
Dim Grammar As ISpeechRecoGrammar
Dim lex As SpUnCompressedLexicon

Dim m_bRecoRunning As Boolean
Dim m_cChars As Integer


Private Sub Form_Load()
SetState False
m_cChars = 0
End Sub

Private Sub btnStart_Click()
Debug.Assert Not m_bRecoRunning

' Initialize recognition context object and grammar object, then
' start dictation
If (RecoContext Is Nothing) Then
Debug.Print "Initializing SAPI reco context object..."
Set RecoContext = New SpSharedRecoContext
Set Grammar = RecoContext.CreateGrammar(1)
Grammar.DictationLoad
End If

Grammar.DictationSetState SGDSActive
SetState True
End Sub

Private Sub btnStop_Click()
Debug.Assert m_bRecoRunning
Grammar.DictationSetState SGDSInactive
SetState False
End Sub

' This function handles Recognition event from the reco context object.
' Recognition event is fired when the speech recognition engines recognizes
' a sequences of words.
Private Sub RecoContext_Recognition(ByVal StreamNumber As Long, _
ByVal StreamPosition As Variant, _
ByVal RecognitionType As SpeechRecognitionType, _
ByVal Result As ISpeechRecoResult _
)
Dim strText As String
strText = Result.PhraseInfo.GetText
Debug.Print "Recognition: " & strText & ", " & _
StreamNumber & ", " & StreamPosition

' Append the new text to the text box, and add a space at the end of the
' text so that it looks better
txtSpeech.SelStart = m_cChars
txtSpeech.SelText = strText & " "
m_cChars = m_cChars + 1 + Len(strText)
End Sub

' This function handles the state of Start and Stop buttons according to
' whether dictation is running.
Private Sub SetState(ByVal bNewState As Boolean)
m_bRecoRunning = bNewState
btnStart.Enabled = Not m_bRecoRunning
btnStop.Enabled = m_bRecoRunning
End Sub


It is a voice recognition program dealing with SAPI. My problem is, some words are not recognized (i.e. I will say "Gevalia" and it will either find a 'close' word, or nothing at all. I have found a few hints around that you can add words along with how they are pronounced to your computers grammar dictionary, but haven't found out how. Does anyone know?

LostAngel
01-02-2008, 05:22 AM
Anyone?

the master
01-02-2008, 06:05 AM
What is the error that you get when you try to add a word?

LostAngel
01-02-2008, 06:21 AM
Well, I tried the following:

Dim lex As SpUnCompressedLexicon
lex.AddPronunciation "",409,SPSUnknown,"ga val e a"


I get the following error:

object variable or with block variable not set...im not sure if im doing it right as I havent found any VB6 examples.

the master
01-02-2008, 06:26 AM
Try this


Dim lex As SpUnCompressedLexicon
set lex = new spuncompressedlexicon
lex.AddPronunciation "",409,SPSUnknown,"ga val e a"

LostAngel
01-02-2008, 06:37 AM
Method 'AddPronunciation' of object 'ISpeechLexicon' failed.

the master
01-02-2008, 06:42 AM
Thats probably because you didnt specify a word as the first argument

LostAngel
01-02-2008, 06:43 AM
that was a misstype in my code i wrote in the post...in my code in vb i have a word.

the master
01-02-2008, 06:48 AM
pszPronunciation
[in] Null-terminated pronunciation of the word in the NUM phone set. Multiple pronunciations may be added for a single word. The length must be equal to or less than SP_MAX_PRON_LENGTH. pszPronunciation may be NULL.

Try this

lex.AddPronunciation "<Insert word>",409,SPSUnknown,"ga val e a" & vbnullchar


If that doesnt work then im out of ideas

LostAngel
01-02-2008, 06:51 AM
same error

the master
01-02-2008, 08:29 AM
After a bit of searching on google i found something else

the only thing you have to worry about is to make sure and use the
standard SAPI phoneme set for your pronunciations. The standard phone sets
are documented in the SAPI5.1 documentation

I guess using a non standard one would cause an error

LostAngel
01-02-2008, 08:41 AM
I too thought this, so i decided to try and add a simpler word...with the phenomes listed on the documentation and it still didnt work :(

the master
01-02-2008, 09:45 AM
Have you read the SAPI5.1 documentation?

LostAngel
01-02-2008, 11:00 AM
Yeah, but there is no examples of the 100% correct way of doing what i need in vb6.

MrKoffee
01-17-2008, 08:07 AM
I don't know if you have found the answer yet. However, I was attempting the same thing. I looked through the objects available after running into the same error you received. I found the following works

'Dim addlex As SpUnCompressedLexicon
Dim addlex As SpLexicon
.
.
.
.
'Set addlex = New SpUnCompressedLexicon
Set addlex = New SpLexicon
Set RecoContext = New SpSharedRecoContext
Set Grammar = RecoContext.CreateGrammar(1)
Grammar.DictationLoad

addlex.AddPronunciation "Bob", 1, SPSNoun



Basically I changed from SpUnCompressedLexicon to SpLexicon, the error went away and the name 'Bob' was recognized where it was not previously.


Hope this helps.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum