Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Speech; 
using System.Threading;
using  System.Speech.Recognition ;
using  System.Speech.Synthesis ;    
using  System.Globalization;
using System.IO;
using System.Text; 


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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {


            SpeechRecognitionEngine RecognitionEngine; 
            using (RecognitionEngine = new SpeechRecognitionEngine(new CultureInfo("en-US")))
            {
                RecognitionEngine.SetInputToWaveFile(Server.MapPath("~/speech.wav"));
                RecognitionEngine.LoadGrammar(new DictationGrammar());
                RecognitionResult Result = RecognitionEngine.Recognize();
                
                StringBuilder Output = new StringBuilder(); 
                foreach (RecognizedWordUnit Word in Result.Words) 
                {
                    Output.Append(Word.Text + " ");
                    textBox1.Text = Output.ToString();
                }
               
            }
            

    }
    }
}

i have tried converting voice to text using this code but it keeps on giving me error where it have to read the recording i have recorded on the
C#
RecognitionEngine.SetInputToWaveFile(Server.MapPath("~/speech.wav"));

The error is this, system invalide operation exception. it cant read the file
Posted
Updated 7-May-12 23:58pm
Comments
Bernhard Hiller 9-May-12 3:17am    
Replace
RecognitionEngine.SetInputToWaveFile(Server.MapPath("~/speech.wav"));
by
string myFile = Server.MapPath("~/speech.wav");
System.Diagnostics.Debug.WriteLine("Filename: " + myFile);
RecognitionEngine.SetInputToWaveFile(myFile);
and verify that myFile really exists!!!
Also verify that the format is correct - PCM will surely do, compressed format may fail.

The code in Button1_Click is executed on the server side! Are you sure that the file exists on that place on the server (!) and is accessible for the IIS user?
 
Share this answer
 
This error comes mostly when application Failed to map the path. So make yourpath of that file is correct and file exists there.
 
Share this answer
 
Copy the wav file into your project and give full path(You can do it by dragging the wav file into your application)

RecognitionEngine.SetInputToWaveFile(Server.MapPath("~/speech.wav"));

Replace with

RecognitionEngine.SetInputToWaveFile(@"C:\Desktop\IT\SpeechText90\8mm-devil.wav");

Hope this helps.
Happy Coding :)
 
Share this answer
 
i cant get it to work and this is due like 2mrw
 
Share this answer
 
Comments
bbirajdar 8-May-12 9:25am    
Please improve your question or add as a comment. Do not post as solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900