Speech API on web application

Joined
Jan 19, 2010
Messages
1
Reaction score
0
Hi, we have a form based application using SAPI 5 and we need to migrate it to web based application.
We have made tests with the SpVoice object and it works great in the Form application and the web application, the issue comes with the SpSharedRecoContext object, it doesn't appear to work in the web application, the RecoContext_Recognition event isn't triggered.

The Web application runs, but doesn't recognize voice. Here is the code:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SpeechLib;

namespace WebApplication4
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
int accuracyLimit = 0;
float accuracyMax = 0.1F; //to avoid divide by zero
string firstRecognition = "";
private SpeechLib.SpSharedRecoContext objRecoContext;
ISpeechGrammarRule rule;
ISpeechGrammarRuleState state;
ISpeechRecoGrammar grammar;
SpVoice ob;
private void initSAPI()//STARTS THE RECOGNITION ENGINE
{
try
{
objRecoContext = new SpeechLib.SpSharedRecoContext();
objRecoContext.AudioLevel +=
new _ISpeechRecoContextEvents_AudioLevelEventHandler(RecoContext_VUMeter);
objRecoContext.Recognition +=
new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
objRecoContext.EventInterests = SpeechLib.SpeechRecoEvents.SRERecognition |
SpeechLib.SpeechRecoEvents.SREAudioLevel;
// objRecoContext.StartStream += new _ISpeechRecoContextEvents_StartStreamEventHandler(RecoContext_StartStream);

//create grammar interface with ID = 0
grammar = objRecoContext.CreateGrammar(0);
}
catch (Exception ex)
{
Label1.Text = "Exeption (Init SAPI)\n" + ex.ToString();
}
}
/*VOLUME METER*/
public void RecoContext_VUMeter(int StreamNumber, object StreamPosition, int e)
{
Label2.Text = "Volumen: " + e.ToString();
}
/*ADDS WORDS TO THE GRAMMAR*/
private void SAPIGrammarFromArrayList(ArrayList phraseList)
{
object propertyValue = "";
int i;
for (i = 0; i < phraseList.Count; i++)
{
rule = grammar.Rules.Add(phraseList.ToString(), SpeechRuleAttributes.SRATopLevel, i + 100);

//add new word to the rule
state = rule.InitialState;
propertyValue = "";
//state.AddWordTransition(null, command1.phrase, " ",
// SpeechGrammarWordType.SGLexical, "",
// 0, ref propertyValue, 1F);
state.AddWordTransition(null, phraseList.ToString(), " ",
SpeechGrammarWordType.SGLexical, "",
0, ref propertyValue, 1F);
//commit rules
grammar.Rules.Commit();

//make rule active (needed for each rule)
grammar.CmdSetRuleState(phraseList.ToString(), SpeechRuleState.SGDSActive);
}
}
/*EVENT TRIGGERED IN A RECOGNITION EVENT*/
public void RecoContext_Recognition(int StreamNumber, object StreamPosition,
SpeechRecognitionType RecognitionType, ISpeechRecoResult e)
{
//get phrase
string phrase = e.PhraseInfo.GetText(0, -1, true);
TextBox2.Text = TextBox2.Text + phrase;
Label1.Text = phrase;
}

protected void Button1_Click(object sender, EventArgs e)
{
//THIS BLOCK WORKS RIGHT
SpVoice ob = new SpVoice();
ob.Rate = -100;
ob.Speak(TextBox1.Text,SpeechVoiceSpeakFlags.SVSFDefault);
SpStream str = new SpStream();
}

protected void Button2_Click(object sender, EventArgs e)
{
//THIS ONE DOESN'T
ArrayList vec = new ArrayList(10);
initSAPI();//STARTS THE RECOGNITION ENGINE
SAPIGrammarFromArrayList(vec);
grammar.State = SpeechLib.SpeechGrammarState.SGSEnabled;
grammar.DictationLoad(null, SpeechLoadOption.SLOStatic);
grammar.DictationSetState(SpeechRuleState.SGDSActive);
}
}
}

Any help? Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top