The compiled assembly runs and recognizes my speech great in Windows XP
SP2.
Running the same code in Vista RTM however doesn't work. The
SpeechDetected event fires, but the Hypothesized, Recognised and
Rejected events never fire.
Vista RTM is setup correctly since the built in Speech Recognition
works fine - I can "start listening", "start notepad" etc etc - no
dramas - so it isn't that my mic/sound card are not setup.
Any ideas? Googling around only seems to turn up BETA2 samples and the
Windows SDK samples only has TTS samples - no recognition ones.
Code sample below for how I am initializing the SpeechRecognizer class.
It is a command interface ie: I supply an array of strings that I want
detected (as opposed to dictation).
cheers!
<code>
public void VoiceCommandsSet(string[] commands)
{
GrammarBuilder grammarBuilder = new GrammarBuilder();
grammarBuilder.Append(new Choices(commands));
Grammar grammar = new Grammar(grammarBuilder);
grammar.Enabled = true;
_speechRecogniser.UnloadAllGrammars();
_speechRecogniser.LoadGrammar(grammar);
_speechRecogniser.SpeechHypothesized += new
EventHandler<SpeechHypothesizedEventArgs>(_speechRecogniser_SpeechHypothesized);
_speechRecogniser.SpeechRecognized += new
EventHandler<SpeechRecognizedEventArgs>(_speechRecogniser_SpeechRecognized);
}
</code>
Some aspects of SRGS grammar support for example dont work... i expect that
you should example what is actually supported on XP.
Full SAPI 5.3 functionality is only available on vista
<ItagSo...@gmail.com> wrote in message
news:1165013871....@16g2000cwy.googlegroups.com...
> Hey all,
> I have some code that I converted to use .NET 3.0, System.Speech
> instead of the SAPI interop.
>
> The compiled assembly runs and recognizes my speech great in Windows XP
> SP2.in
The problem though is my code *works* on XP, but *doesn't work* on
Vista.
I understand that the SAPI engine is newer in Vista - but I would
expect that the System.Speech library would present a layer of
abstraction and work (at least with basic functionality) on XP and
Vista....and if there were a problem then it would be things working in
Vista and not in XP.
No exceptions are thrown in Vista by the code. It runs happily while
ignoring any speech I give it.
Are any of the applications you use downloadable on the web somewhere?
If I can run it on my machine and it still doesn't work (but works on
yours) then it would indicate a problem with my build (rather than a
problem with my code).
Vista also has a different version of the recognition engine, which normally
should be more accurate, but could give different results in certain cases.
"itagger" <ItagSo...@gmail.com> wrote in message
news:1166499594.4...@j72g2000cwa.googlegroups.com...
I was using the SpeechRecognizer class - which as you pointed out seems
to fire up the Speech System UI in Vista and not much else :)
I switched to using the SpeechRecognitionEngine class and managed to
get it all working.
Sample source code below for anyone with a similar problem.
The compiled exe executes and works in both XP sp2 and Vista RTM.
thanks again!
using System;
using System.Speech;
using System.Speech.Recognition;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
namespace SpeechTest
{
class Program
{
static void Main(string[] args)
{
EnumerateEngines();
args = CheckArguments(args);
CommandListener listener = new CommandListener();
listener.SetCommands(args);
listener.Run();
}
private static string[] CheckArguments(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Setting up default words. Enter your
own words via command line arguments");
args = new string[] { "music", "word" };
}
Console.Write("Now listening for...");
foreach (string word in args)
{
Console.Write(String.Format("'{0}', ", word));
}
Console.WriteLine("\r\n(Press a key to stop listening)");
return args;
}
private static void EnumerateEngines()
{
Console.WriteLine("The following engines are available");
foreach (RecognizerInfo config in
SpeechRecognitionEngine.InstalledRecognizers())
{
Console.WriteLine(config.Name + " " +
config.Description);
}
}
}
class CommandListener
{
SpeechRecognitionEngine _speechRecogniser;
public CommandListener()
{
_speechRecogniser = new SpeechRecognitionEngine();
_speechRecogniser.SetInputToDefaultAudioDevice();
_speechRecogniser.SpeechDetected += new
EventHandler<SpeechDetectedEventArgs>(_speechRecogniser_SpeechDetected);
_speechRecogniser.SpeechHypothesized += new
EventHandler<SpeechHypothesizedEventArgs>(_speechRecogniser_SpeechHypothesized);
_speechRecogniser.SpeechRecognitionRejected += new
EventHandler<SpeechRecognitionRejectedEventArgs>(_speechRecogniser_SpeechRecognitionRejected);
_speechRecogniser.SpeechRecognized += new
EventHandler<SpeechRecognizedEventArgs>(_speechRecogniser_SpeechRecognized);
_speechRecogniser.AudioStateChanged += new
EventHandler<AudioStateChangedEventArgs>(_speechRecogniser_AudioStateChanged);
_speechRecogniser.AudioSignalProblemOccurred += new
EventHandler<AudioSignalProblemOccurredEventArgs>(_speechRecogniser_AudioSignalProblemOccurred);
NotifyEvent("Loaded default engine - {0}",
_speechRecogniser.RecognizerInfo.Name);
}
#region Event Handlers
void _speechRecogniser_AudioSignalProblemOccurred(object
sender, AudioSignalProblemOccurredEventArgs e)
{
NotifyEvent("Audio problem {0}",
e.AudioSignalProblem.ToString("G"));
}
void _speechRecogniser_AudioStateChanged(object sender,
AudioStateChangedEventArgs e)
{
NotifyEvent("Audio state now {0}",
e.AudioState.ToString("G"));
}
void _speechRecogniser_SpeechRecognized(object sender,
SpeechRecognizedEventArgs e)
{
NotifyEvent("Recognized '{0}' at {1} seconds",
e.Result.Text, e.Result.Audio.AudioPosition);
}
void _speechRecogniser_SpeechRecognitionRejected(object sender,
SpeechRecognitionRejectedEventArgs e)
{
NotifyEvent("RecognitionRejected '{0}' at {1} seconds",
e.Result.Text, e.Result.Audio.AudioPosition);
}
void _speechRecogniser_SpeechHypothesized(object sender,
SpeechHypothesizedEventArgs e)
{
NotifyEvent("Hypothesized '{0}' at seconds",
e.Result.Text);
}
void _speechRecogniser_SpeechDetected(object sender,
SpeechDetectedEventArgs e)
{
NotifyEvent("Detected speech at {0} seconds",
e.AudioPosition.TotalSeconds);
}
#endregion
public void SetCommands(string[] commands)
{
GrammarBuilder grammarBuilder = new GrammarBuilder();
grammarBuilder.Culture =
_speechRecogniser.RecognizerInfo.Culture;
grammarBuilder.Append(new Choices(commands));
Grammar grammar = new Grammar(grammarBuilder);
_speechRecogniser.UnloadAllGrammars();
_speechRecogniser.LoadGrammar(grammar);
_speechRecogniser.RecognizeAsync(RecognizeMode.Multiple);
}
public void Run()
{
while (!Console.KeyAvailable)
{
Thread.Sleep(100);
}
_speechRecogniser.Dispose();
}
private static void NotifyEvent(string format, params object[]
args)
{
Console.WriteLine(string.Format(format, args));
}
}
}