Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 117,541 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,689 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



SR from audio file?

 
Reply to this topicStart new topic

SR from audio file?

hiphop_13
post 12 Jul, 2008 - 06:36 AM
Post #1


New D.I.C Head

*
Joined: 4 Jun, 2007
Posts: 36



Thanked 1 times
My Contributions


Hi,

This speech recognition code recognizes the sound from a microphone.
What i need is to change the source from microphone to an audio file.
How could i change the source?

csharp

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using SpeechLib;
using System.IO;
using System.Threading;


namespace WindowsApplication14
{
public partial class Form1 : Form
{
private SpeechLib.SpInProcRecoContext obj;
private SpeechLib.SpSharedRecoContext objRecoContext;
private SpeechLib.ISpeechRecoGrammar grammar;
private string strData = "No recording yet";

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
try
{
if (objRecoContext == null)
{
objRecoContext = new SpeechLib.SpSharedRecoContext();
objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(RecoContext_Recognition);
grammar = objRecoContext.CreateGrammar(1);
grammar.DictationLoad("", SpeechLoadOption.SLOStatic);
}
grammar.DictationSetState(SpeechRuleState.SGDSActive);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception caught when initializing SAPI." + " This application may not run correctly.\r\n\r\n" + ex.ToString(), "Error");
}

}


private void button2_Click(object sender, EventArgs e)
{
grammar.DictationSetState(SpeechRuleState.SGDSInactive);

}

public void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
{
strData = Result.PhraseInfo.GetText(0, -1, true);
Debug.WriteLine("Recognition: " + strData + ", " + StreamNumber + ", " + StreamPosition);
textBox1.Text += " " + strData;
//strData = strData;
}

private void button3_Click(object sender, EventArgs e)
{
try
{
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice Voice = new SpVoice();
if (checkBox1.Checked)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
sfd.Title = "Save to a wave file";
sfd.FilterIndex = 2;
sfd.RestoreDirectory = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
SpFileStream SpFileStream = new SpFileStream();
SpFileStream.Open(sfd.FileName, SpFileMode, false);
Voice.AudioOutputStream = SpFileStream;
Voice.Speak("You recorded the following message " + strData, SpFlags);
Voice.WaitUntilDone(Timeout.Infinite);
SpFileStream.Close();
}
}
else
{
Voice.Speak("You recorded the following message" + strData, SpFlags);
}
}
catch
{
MessageBox.Show("Speak error", "SimpleTTS", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void button4_Click(object sender, EventArgs e)
{


File.WriteAllText("C:\\Documents and Settings\\$..Hiba..$\\Desktop\\s.txt", textBox1.Text);


}


}
}





This form contains 4 buttons, a multiline textbox and a checkbox

Thanks
User is offlineProfile CardPM

Go to the top of the page


Martyr2
post 12 Jul, 2008 - 09:02 AM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 4,604



Thanked 116 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


First of all...

1) Setup a SpeechLib.SpInprocRecognizer object.
2) Then create a SpeechLib.SpFileStream object.
3) Use the SpFileStream method called "open" and give it the filename of your wav file as a parameter.
4) On your SpInprocRecognizer object there is a property called "AudioInputStream". Set this property to the SpFileStream object you just setup with the wav file.

5) Lastly set your objRecoContext using the SpInprocRecognizer.CreateRecoContext method and you are off to the races.

I hope this step by step helps you out. Enjoy!

"At DIC we be speech recognizing code ninjas... we just don't recognize the trash coming out of their mouth" decap.gif

User is offlineProfile CardPM

Go to the top of the page

hiphop_13
post 13 Jul, 2008 - 10:10 AM
Post #3


New D.I.C Head

*
Joined: 4 Jun, 2007
Posts: 36



Thanked 1 times
My Contributions


Thanks a lot for ur help, I got it solved thanks:).

It seems that ur an expert in SR so i have another question for u, hope ul have the answer.

If im using SR from a micro is there a way i could differentiate the people speaking i.e know that it's now person A now person C ...

Thanks
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 05:23PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month