Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
AnswerRe: Trick to Access derived class method from base Pin
Keith Barrow21-May-13 3:59
professionalKeith Barrow21-May-13 3:59 
AnswerRe: Trick to Access derived class method from base Pin
Keld Ølykke21-May-13 5:36
Keld Ølykke21-May-13 5:36 
AnswerRe: Trick to Access derived class method from base Pin
Dave Kreskowiak21-May-13 6:05
mveDave Kreskowiak21-May-13 6:05 
AnswerRe: Trick to Access derived class method from base Pin
Bernhard Hiller21-May-13 20:48
Bernhard Hiller21-May-13 20:48 
AnswerRe: Trick to Access derived class method from base Pin
dinesh.17krishnan21-May-13 22:12
dinesh.17krishnan21-May-13 22:12 
GeneralRe: Trick to Access derived class method from base Pin
Keld Ølykke22-May-13 19:35
Keld Ølykke22-May-13 19:35 
AnswerRe: Trick to Access derived class method from base Pin
Ravi Bhavnani22-May-13 4:59
professionalRavi Bhavnani22-May-13 4:59 
Questionhow to save voice from modem as a wav file whic can be accessed by speech sdk for processing Pin
samweps21-May-13 1:16
samweps21-May-13 1:16 
hi all, its my first time here...i am writing an app that will receive voice from a Huawei E1752 modem, save it as a wav file and the file is later accessed by the speech SDK for processing. i have inquired from Google(my best friend) and also from past articles on this site and i am able to save something to the wav file but its not really the voice i expect to be saved, and when the speech SDK accesses the file, it brings an error saying (the audio file is not a recognizable format). how can i save the audio from the modem to a format that can be recognized by the speech sdk. i have been able to write this
thanks.

C#
namespace joaninne
{
    public partial class Form1 : Form
    {

        //static bool _continue;
        static SerialPort _SerialPort1;
        byte[] buffer;
        FileStream file;


        public Form1()
        {
            InitializeComponent();

            file = File.Open(@"D:\speechtestfiles.wav", FileMode.Create);
            //buffer = new byte[60 * 1024];
            //Create a new modem port instance with the required settings
            _SerialPort1 = new SerialPort("COM31", 9600, Parity.None, 8, StopBits.One);
            _SerialPort1.DtrEnable = true;
            _SerialPort1.RtsEnable = true;
 
            _SerialPort1.ReadTimeout = SerialPort.InfiniteTimeout;

           
              
          
            //open the serial port
            _SerialPort1.Open();

           // _SerialPort1.Write("AT\r");          

           // Thread.Sleep(1000);

            _SerialPort1.Write("ATS0=1\r");
            buffer = new byte[100 * 1024];
            _SerialPort1.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
            Thread.Sleep(1000);
              
         
            //close the modem port
             _SerialPort1.Close();
            file.Close();
            file.Dispose();
            
            // Create a SpeechRecognitionEngine object for the default recognizer in the en-US locale since we have chosen
            // american english as our language 
            using (SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new CultureInfo("en-US")))
            {

                // Create a grammar.
                Choices appliances = new Choices(new string[] { "fan", "lights" });
                Choices Commands = new Choices(new string[] { "on", "off" });

                GrammarBuilder gb = new GrammarBuilder();
                gb.Append("Please turn the");
                gb.Append(appliances);
                gb.Append(Commands);

                // Create a Grammar object and load it to the recognizer.
                Grammar g = new Grammar(gb);
                recognizer.LoadGrammarAsync(g);

                // Attach event handlers.
                recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
                recognizer.SpeechRecognitionRejected +=
                new EventHandler<SpeechRecognitionRejectedEventArgs>(recognizer_SpeechRecognitionRejected);

                var isReady = false;
                while (!isReady)
                {
                    isReady = IsFileReady(@"D:\speechtestfiles.wav");
                }
                    // Set the input to the recognizer i.e to the audio file that was stored
                    recognizer.SetInputToWaveFile(@"D:\speechtestfiles.wav");



                    // Start asynchronous, continuous recognition.
                    recognizer.RecognizeAsync(RecognizeMode.Multiple);

                
                    // Keep the console window open.
                   // Console.ReadLine();
              
               
            }
            //close the port
            //_SerialPort1.Close();
        }

        private void sp_DataReceived(object Sender, SerialDataReceivedEventArgs e)
        {
          
           
            int x = _SerialPort1.BytesToRead;
            _SerialPort1.Read(buffer, 0, x);
            file.Write(buffer, 0, x);
           
        }

        public static bool IsFileReady(String file)
        {
            //if the file can be opened for exclusive access, it means the file is nolonger locked by another process
            try
            {
                using (FileStream inputStream=File.Open(file,FileMode.Open,FileAccess.Read,FileShare.None))
                {
                    if (inputStream.Length>0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
        }

        // Handle the SpeechRecognitionRejected event.
        public static void recognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
        {
            foreach (RecognizedPhrase phrase in e.Result.Alternates)
            {
                Console.WriteLine("  Rejected phrase: " + phrase.Text);

            }
        }

        // Handle the SpeechRecognized event.
        public static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string _detected = (e.Result.Text);

            //shows the list of possible phrases
            string _recognised1 = " Please turn the lights on";
            //string _recognised2 = " Please turn the fan on";
            //string _recognised3 = " Please turn the lights off";
            //string _recognised4 = " Please turn the fan off";

            //sends the "turn the light on" command to the appliances
            if (String.Compare(_recognised1, _detected) == 0)
            {
                //string fileLightsOn = @"D:\\wep\WAVE\Lights on.wav";

                PortAccess.Output(888, 1);

                //also sends the confirmation command to the user


            }
            else
            {
                //send voice message to user notifying them that an invalid command was sent


            }
        }
    }

}

AnswerRe: how to save voice from modem as a wav file whic can be accessed by speech sdk for processing Pin
Richard MacCutchan21-May-13 2:55
mveRichard MacCutchan21-May-13 2:55 
QuestionAnother tcp / net question.. Pin
Member 986287220-May-13 23:49
Member 986287220-May-13 23:49 
AnswerRe: Another tcp / net question.. Pin
Eddy Vluggen21-May-13 3:02
professionalEddy Vluggen21-May-13 3:02 
QuestionGenerics in C# Pin
srikumarrampa20-May-13 23:37
srikumarrampa20-May-13 23:37 
AnswerRe: Generics in C# Pin
Abhinav S21-May-13 1:08
Abhinav S21-May-13 1:08 
GeneralRe: Generics in C# Pin
srikumarrampa21-May-13 18:04
srikumarrampa21-May-13 18:04 
AnswerRe: Generics in C# Pin
Alan N22-May-13 4:21
Alan N22-May-13 4:21 
GeneralRe: Generics in C# Pin
srikumarrampa22-May-13 19:37
srikumarrampa22-May-13 19:37 
AnswerRe: Generics in C# Pin
BillWoodruff23-May-13 2:23
professionalBillWoodruff23-May-13 2:23 
QuestionPassing Cursor Coordinates as Parameters Pin
ASPnoob20-May-13 21:52
ASPnoob20-May-13 21:52 
AnswerRe: Passing Cursor Coordinates as Parameters Pin
Pete O'Hanlon20-May-13 22:01
mvePete O'Hanlon20-May-13 22:01 
GeneralRe: Passing Cursor Coordinates as Parameters Pin
ASPnoob20-May-13 22:05
ASPnoob20-May-13 22:05 
AnswerRe: Passing Cursor Coordinates as Parameters Pin
OriginalGriff20-May-13 22:52
mveOriginalGriff20-May-13 22:52 
GeneralRe: Passing Cursor Coordinates as Parameters Pin
ASPnoob21-May-13 16:38
ASPnoob21-May-13 16:38 
GeneralRe: Passing Cursor Coordinates as Parameters Pin
lukeer21-May-13 21:47
lukeer21-May-13 21:47 
GeneralRe: Passing Cursor Coordinates as Parameters Pin
OriginalGriff21-May-13 22:21
mveOriginalGriff21-May-13 22:21 
QuestionPropertyGrid Multiple Objects Selection Pin
vvino202020-May-13 20:48
professionalvvino202020-May-13 20:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.