I have been reading through the forums and scouring for information to help me
integrate pocketsphinx in a vb.net project but have found very little
information. I have created a wrapper class using interop services to call the
pocketsphinx methods that I need but I am running into numerous issues. Is
there anyone who has been down this road before who I can beg assistance from?
Is there any sample .Net interface code out there that I can look at to get
ideas from?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For your amusement, here is the code for my interface class as it currently
stands. My current issue is that it locks up the process with "vshost32.exe
has stopped working" when it gets to the call to ps_start_utt.
Imports System.Runtime.InteropServices
Imports System.Text
Public Class SphinxInterface
<DllImport("sphinxbase.dll")> _
Public Shared Function cmd_ln_init(ByVal inout_cmdln As Object, ByVal defn As Object, ByVal strict As Integer, ByVal ParamArray args() As String) As Integer
End Function
'Dim conf = cmd_ln_init(Nothing, Nothing, True, "-hmm", modeldir & "/hmm/en_US/hub4wsj_sc_8k", "-lm", modeldir & "/lm/en/turtle.DMP", "-dict", modeldir & "/lm/en/turtle.dic", Nothing)
<DllImport("pocketsphinx.dll")> _
Public Shared Function ps_start_utt(ByRef ps_decoder_t As Object, ByRef uttid As StringBuilder) As Integer
End Function
<DllImport("pocketsphinx.dll")> _
Public Shared Function ps_process_raw(ByRef ps_decoder_t As Object, ByVal buf() As Int16, ByVal len As UInt32, ByVal no_search As Integer, ByVal full_utt As Integer) As Integer
End Function
<DllImport("pocketsphinx.dll")> _
Public Shared Function ps_end_utt(ByRef ps_decoder_t As Object) As Integer
End Function
<DllImport("pocketsphinx.dll")> _
Public Shared Function ps_get_utt(ByRef ps_decoder_t As Object, ByRef score As Integer, ByRef uttid As StringBuilder) As String
End Function
Public Function GetText(ByVal buf() As Int16) As String
Dim config As Object
Dim returnCode As Integer
Dim Hyp As String = ""
Dim ModelDir As String = "D:\CMUSphinx\Source\pocketsphinx\model"
Dim ps As Object = Nothing
Dim uttID As New StringBuilder("sphinx")
Dim tmp() As Int16
Dim Score As Integer = -1
returnCode = cmd_ln_init(Nothing, Nothing, True, "-hmm", ModelDir & "/hmm/en_US/hub4wsj_sc_8k", "-lm", ModelDir & "/lm/en/turtle.DMP", "-dict", ModelDir & "/lm/en/turtle.dic", Nothing)
If returnCode >= 1 Then
[color=red] returnCode = ps_start_utt(ps, uttID)[/color]
If returnCode >= 0 Then
For i As Integer = 0 To buf.GetUpperBound(0) Step 512
ReDim tmp(511)
Dim len As Integer = IIf(i <= buf.GetUpperBound(0), 512, buf.GetUpperBound(0) - i)
Array.Copy(buf, i, tmp, 0, len)
returnCode = ps_process_raw(ps, tmp, len, 0, 0)
Next
If returnCode >= 0 Then
Hyp = ps_get_utt(ps, Score, uttID)
End If
End If
End If
Return Hyp
End Function
End Class
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is the vc sln file that is a good starting point. You should probably
post the log you see in the console, also, make sure that those paths are
correct.
I refer to /hmm/en_US/hub4wsj_sc_8k
Isnt windows paths \ instead of /?
Make sure also the files are indeed there.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I verified that the paths are correct and that the files exist. I also changed
the "/" to "\" as you suggested, good catch there. However, I still get the
same result. What console are you referring to that I should post the log
from?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There should be a console that outputs the log, otherwise we would just be
randomly guessing. I know c# has, vb.net should also. Make sure you have the
console view shown, often it indicates where the error is.
Then paste it here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks so much for being willing to help. I have an Output window but it just
shows the information regarding the managed code but once it calls the
unmanaged library it has nothing. It doesn't show any exception information in
the managed code.
However, I did find a report of the exception in the application event viewer.
It says:
I have been reading through the forums and scouring for information to help me
integrate pocketsphinx in a vb.net project but have found very little
information. I have created a wrapper class using interop services to call the
pocketsphinx methods that I need but I am running into numerous issues. Is
there anyone who has been down this road before who I can beg assistance from?
Is there any sample .Net interface code out there that I can look at to get
ideas from?
For your amusement, here is the code for my interface class as it currently
stands. My current issue is that it locks up the process with "vshost32.exe
has stopped working" when it gets to the call to ps_start_utt.
Oh Interop fun :)
There is the vc sln file that is a good starting point. You should probably
post the log you see in the console, also, make sure that those paths are
correct.
I refer to /hmm/en_US/hub4wsj_sc_8k
Isnt windows paths \ instead of /?
Make sure also the files are indeed there.
I verified that the paths are correct and that the files exist. I also changed
the "/" to "\" as you suggested, good catch there. However, I still get the
same result. What console are you referring to that I should post the log
from?
There should be a console that outputs the log, otherwise we would just be
randomly guessing. I know c# has, vb.net should also. Make sure you have the
console view shown, often it indicates where the error is.
Then paste it here.
Thanks so much for being willing to help. I have an Output window but it just
shows the information regarding the managed code but once it calls the
unmanaged library it has nothing. It doesn't show any exception information in
the managed code.
However, I did find a report of the exception in the application event viewer.
It says:
From what I have read, BEX is a buffer overlow exception. Do you see anything
that would explain that in my declaration of ps_start_utt?
I suspect that it has to do with my declaring the ps_decoder_t parameter as
Object but I'm not sure how else that should be declared in vb.net.
You need to get the unmanaged logs.
Also, I see a possible error:
You are passing in a null ps value to ps_start_utt.
its supposed to be ps=ps_init(returnCode)
then ps_start_utt(ps,whatever)
So one error is your passing in a null ps. Try that, if it doesnt work figure
out how to get logs in unmanaged code.