Today I will Show you Voice Recognition In Windows Phone 7 (WP7) or Voice to Text In Windows Phone 7 (WP7).
This Is a very Important Topic for Which I searched a but could not get any Success .
We can not add System.Speech.Recognition .dll in Windows Phone 7 if you try to add this dll in Windows Phone 7 Project you will get an Error.
This Is a very Important Topic for Which I searched a but could not get any Success .
We can not add System.Speech.Recognition .dll in Windows Phone 7 if you try to add this dll in Windows Phone 7 Project you will get an Error.
So the question is then how will we recognize the voice in Windows Phone 7 .
there is an architecture to follow this architecture we can easily recognized Voice on Windows Phone.
So,
First We Recode Voice From Windows Phone 7
Then Send This voice to Web Service having Voice Recognition Facility
And We Getting Response from Server .
Now Here First We make a WCF(.SVC) Web service.
in web add a following Method
add Foloowing Code in Pageload event
Here the method will Reply to server the following Result
1) on Button Press event I start Voice Recording.
2) another Button Press event I stop Voice Recording.
3)There is a Button Name Recognized press event through which i send Recoded voice to web Service and Result will be show in a textbock.
Note this Service only Recognizes Those words that you Define in Dictionary .
SOURCE CODE DOWNLOAD
Or
SOURCE CODE DOWNLOAD (Recommended)
Some Out put Screen Short
there is an architecture to follow this architecture we can easily recognized Voice on Windows Phone.
So,
First We Recode Voice From Windows Phone 7
Then Send This voice to Web Service having Voice Recognition Facility
And We Getting Response from Server .
Now Here First We make a WCF(.SVC) Web service.
in web add a following Method
public string RecognizeSpeech(byte[] speechToParse, int sampleRate)
{
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
/* if (_grammar == null)
InitializeGrammar();
sre.LoadGrammar(_grammar);*/
Grammar testGrammar =
new Grammar(new GrammarBuilder("Ya Allah"));
testGrammar.Name = "Test Grammar";
sre.LoadGrammar(testGrammar);
Grammar testgrammar1 = new Grammar(new GrammarBuilder("Android"));
testgrammar1.Name = "Test Grammar";
sre.LoadGrammar(testgrammar1);
Grammar testgrammar2 = new Grammar(new GrammarBuilder("Windows Phone"));
testgrammar2.Name = "Test Grammar";
sre.LoadGrammar(testgrammar2);
Grammar testgrammar3 = new Grammar(new GrammarBuilder("Pakistan"));
testgrammar3.Name = "Test Grammar";
sre.LoadGrammar(testgrammar3);
Grammar testgrammar4 = new Grammar(new GrammarBuilder("Sajjad Awan"));
testgrammar4.Name = "Test Grammar";
sre.LoadGrammar(testgrammar4);
//sre.LoadGrammar(new DictationGrammar());
Choices cities = new Choices(new string[] { "Los Angeles", "New York",
"Chicago", "San Francisco", "Miami", "Dallas","landhi" });
//Choices
GrammarBuilder gb = new GrammarBuilder();
gb.Append("I want to fly from");
gb.Append(cities);
gb.Append("to");
gb.Append(cities);
// Construct a Grammar object and load it to the recognizer.
Grammar cityChooser = new Grammar(gb);
cityChooser.Name = ("City Chooser");
sre.LoadGrammarAsync(cityChooser);
MemoryStream ms = new MemoryStream(speechToParse);
var formatInfo = new SpeechAudioFormatInfo(sampleRate,
AudioBitsPerSample.Sixteen, AudioChannel.Mono);
sre.SetInputToAudioStream(ms, formatInfo);
var result = sre.Recognize();
ms = null;
if (result == null )
return "?";
else
return result.Text;
}
and Also Add In ServiceContract
[OperationContract]
string RecognizeSpeech(byte[] speechToParse, int sampleRate);
In Windows Phoneadd Foloowing Code in Pageload event
BasicHttpBinding binding = new BasicHttpBinding()
{ MaxReceivedMessageSize = int.MaxValue, MaxBufferSize = int.MaxValue };
EndpointAddress address =
new EndpointAddress(@"http://localhost:40427/SpeechService.svc");
_client = new SpeechServiceClient(binding, address);
/*_client.CreateWavStreamCompleted +=;
new EventHandler(_client_CreateWavStreamCompleted);*/
_client.RecognizeSpeechCompleted +=
new EventHandler(_client_RecognizeSpeechCompleted);
Note In above code you have to generate Event by presings tab Button from key board Two times and not Copy paste Here the method will Reply to server the following Result
void _client_RecognizeSpeechCompleted(object sender,
RecognizeSpeechCompletedEventArgs e)
{
txtRecognized.Text = String.Format("Recognized: {0}", e.Result);
}
For Recoding Voice I use Windows Phone 7 sample Sample Code available on MSDN .1) on Button Press event I start Voice Recording.
2) another Button Press event I stop Voice Recording.
3)There is a Button Name Recognized press event through which i send Recoded voice to web Service and Result will be show in a textbock.
Note this Service only Recognizes Those words that you Define in Dictionary .
SOURCE CODE DOWNLOAD
Or
SOURCE CODE DOWNLOAD (Recommended)
Some Out put Screen Short
The Link not found .I need this source code ,Please
ReplyDeleteWhich link are you talking about??
ReplyDeleteOk The Source Code. There seems to be an error with our 4shared account. Ill make sure you get the file delivered to you through email. Please Subscribe To VisualStudioLearn so that we may know ur email.
ReplyDeletelink die, pls fix it
ReplyDelete