Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System.Speech - works in XP not in Vista?

60 views
Skip to first unread message

ItagSo...@gmail.com

unread,
Dec 1, 2006, 5:57:51 PM12/1/06
to
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.

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>

Chris Smedley

unread,
Dec 7, 2006, 5:32:36 PM12/7/06
to
My understanding is that a number of components with SAPI 5.3 will generate
PLATFORM_NOT_SUPPORTED errors when you attempt to run them on a NON Vista
machine.

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

itagger

unread,
Dec 8, 2006, 6:26:51 PM12/8/06
to
thanks for the reply Chris.

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.

Michael Dunn

unread,
Dec 18, 2006, 6:27:00 AM12/18/06
to
I am able to run speech recognition applications on Vista using the
System.Speech namespace, are you getting an error?

itagger

unread,
Dec 18, 2006, 10:39:54 PM12/18/06
to
Nope - the application runs without error. SpeechDetected event fires.
Recognised, Rejected, Hypothesized events never fire.

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).

Dave Wood [MS]

unread,
Dec 19, 2006, 8:44:09 PM12/19/06
to
Are you using the SpeechRecognition class, or the SpeechRecognitionEngine
class? With the SpeechRecognition class, the main difference I can see
between XP and Vista is that the full speech-enabled UI is running in
parallel with your grammar. Thus there's more perplexity for the engine to
deal with so it's possible that words got recognized by the system as
commands or dictation rather than by your app.

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...

itagger

unread,
Dec 21, 2006, 8:23:19 PM12/21/06
to
Dave
Thank you very much. Your questions pointed me in the right direction.

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));
}
}
}

0 new messages