none
Speech to text RRS feed

  • Question

  • I am doing a project based on Natural Language Processing. I need to convert Speech to Text first and then check it for any grammatical errors in the text. I am stuck with the code for Speech to Text. I need an urgent help. Can anybody help me out with it?
    My email id is pushkarjoshi2007@rediffmail.com

    • Moved by CoolDadTxModerator Monday, November 9, 2009 2:58 PM Not IDE related (From:Visual C# IDE)
    Saturday, November 7, 2009 2:57 PM

Answers

  • Hi,

    You can use  SpeechSynthesizer  for this. To use this you should add System.Speech to your project as reference.

    Here is a sample.

    SpeechSynthesizer s = new SpeechSynthesizer();
    s.SpeakAsync(txtSubject.Text);

    Also here is a full code includes some more functionalities.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Speech.Synthesis;
    
    namespace SystemSpeechMakale
    {
        public partial class frmSynthesizer : Form
        {
            SpeechSynthesizer s;
            public frmSynthesizer()
            {
                InitializeComponent();
                s = new SpeechSynthesizer();
                s.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(s_SpeakProgress);
                s.StateChanged += new EventHandler<StateChangedEventArgs>(s_StateChanged);
                s.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(s_SpeakCompleted);
            }
            private void frmSynthesizer_Load(object sender, EventArgs e)
            {
                FillGenderCombo();
                FillVoiceAgeCombo();
                FillVoicesCombo();
            }
            void s_SpeakProgress(object sender, SpeakProgressEventArgs e)
            {
                lblProgress.Text = e.Text;
              
            }
            
            private void btnSpeak_Click(object sender, EventArgs e)
            {
               if(rbtnGenderAge.Checked)
               {
                    s.SelectVoiceByHints((System.Speech.Synthesis.VoiceGender)cmbGender.SelectedItem, (System.Speech.Synthesis.VoiceAge)cmbAge.SelectedItem);
                }
                else if (rbtnVoice.Checked)
                {
                    s.SelectVoice(cmbVoice.SelectedItem.ToString());
                }
                s.SpeakAsync(txtSubject.Text); 
            }
            void s_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
            {
                lblProgress.Text = "";
            }
            void s_StateChanged(object sender, StateChangedEventArgs e)
            {
                lblState.Text = "Eski durum: " + e.PreviousState.ToString() + " Yeni durum: " + e.State;
            }
    
            private void FillGenderCombo()
            {
                cmbGender.DataSource = Enum.GetValues(typeof(VoiceGender));
            }
            private void FillVoiceAgeCombo()
            {
                cmbAge.DataSource = Enum.GetValues(typeof(VoiceAge));
            }
            private void FillVoicesCombo()
            {
                foreach (InstalledVoice iv in s.GetInstalledVoices())
                {
                    cmbVoice.Items.Add(iv.VoiceInfo.Name);
                }
            }
    
            private void cmbVoice_SelectedIndexChanged(object sender, EventArgs e)
            {
                IEnumerable<InstalledVoice> v = from a in s.GetInstalledVoices() where a.VoiceInfo.Name == cmbVoice.SelectedItem.ToString() select a;
                lblVoiceProperties.Text = "Cinsiyet: " + v.First<InstalledVoice>().VoiceInfo.Gender.ToString() + "\r\nYaş: " + v.First<InstalledVoice>().VoiceInfo.Age.ToString() +
                    "\r\nAçıklama: " + v.First<InstalledVoice>().VoiceInfo.Description;   
            }
    
            private void btnPause_Click(object sender, EventArgs e)
            {
                s.Pause();
            }
    
            private void btnResume_Click(object sender, EventArgs e)
            {
                s.Resume();
            }
    
            private void btnCancel_Click(object sender, EventArgs e)
            {
                Prompt p = s.GetCurrentlySpokenPrompt();
                s.SpeakAsyncCancel(p);
            }
    
            private void btnWav_Click(object sender, EventArgs e)
            {
                s.SetOutputToWaveFile(@"C:\io.wav");
                s.SpeakAsync(txtSubject.Text);  
            }
    
            private void btnSSML_Click(object sender, EventArgs e)
            {
                s.SpeakSsmlAsync(txtSubject.Text);
            }
        }
    }
    


    • Proposed as answer by Tamer Oz Monday, November 9, 2009 4:14 AM
    • Marked as answer by eryang Thursday, November 12, 2009 7:52 AM
    Saturday, November 7, 2009 3:12 PM

All replies

  • Hi,

    You can use  SpeechSynthesizer  for this. To use this you should add System.Speech to your project as reference.

    Here is a sample.

    SpeechSynthesizer s = new SpeechSynthesizer();
    s.SpeakAsync(txtSubject.Text);

    Also here is a full code includes some more functionalities.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Speech.Synthesis;
    
    namespace SystemSpeechMakale
    {
        public partial class frmSynthesizer : Form
        {
            SpeechSynthesizer s;
            public frmSynthesizer()
            {
                InitializeComponent();
                s = new SpeechSynthesizer();
                s.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(s_SpeakProgress);
                s.StateChanged += new EventHandler<StateChangedEventArgs>(s_StateChanged);
                s.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(s_SpeakCompleted);
            }
            private void frmSynthesizer_Load(object sender, EventArgs e)
            {
                FillGenderCombo();
                FillVoiceAgeCombo();
                FillVoicesCombo();
            }
            void s_SpeakProgress(object sender, SpeakProgressEventArgs e)
            {
                lblProgress.Text = e.Text;
              
            }
            
            private void btnSpeak_Click(object sender, EventArgs e)
            {
               if(rbtnGenderAge.Checked)
               {
                    s.SelectVoiceByHints((System.Speech.Synthesis.VoiceGender)cmbGender.SelectedItem, (System.Speech.Synthesis.VoiceAge)cmbAge.SelectedItem);
                }
                else if (rbtnVoice.Checked)
                {
                    s.SelectVoice(cmbVoice.SelectedItem.ToString());
                }
                s.SpeakAsync(txtSubject.Text); 
            }
            void s_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
            {
                lblProgress.Text = "";
            }
            void s_StateChanged(object sender, StateChangedEventArgs e)
            {
                lblState.Text = "Eski durum: " + e.PreviousState.ToString() + " Yeni durum: " + e.State;
            }
    
            private void FillGenderCombo()
            {
                cmbGender.DataSource = Enum.GetValues(typeof(VoiceGender));
            }
            private void FillVoiceAgeCombo()
            {
                cmbAge.DataSource = Enum.GetValues(typeof(VoiceAge));
            }
            private void FillVoicesCombo()
            {
                foreach (InstalledVoice iv in s.GetInstalledVoices())
                {
                    cmbVoice.Items.Add(iv.VoiceInfo.Name);
                }
            }
    
            private void cmbVoice_SelectedIndexChanged(object sender, EventArgs e)
            {
                IEnumerable<InstalledVoice> v = from a in s.GetInstalledVoices() where a.VoiceInfo.Name == cmbVoice.SelectedItem.ToString() select a;
                lblVoiceProperties.Text = "Cinsiyet: " + v.First<InstalledVoice>().VoiceInfo.Gender.ToString() + "\r\nYaş: " + v.First<InstalledVoice>().VoiceInfo.Age.ToString() +
                    "\r\nAçıklama: " + v.First<InstalledVoice>().VoiceInfo.Description;   
            }
    
            private void btnPause_Click(object sender, EventArgs e)
            {
                s.Pause();
            }
    
            private void btnResume_Click(object sender, EventArgs e)
            {
                s.Resume();
            }
    
            private void btnCancel_Click(object sender, EventArgs e)
            {
                Prompt p = s.GetCurrentlySpokenPrompt();
                s.SpeakAsyncCancel(p);
            }
    
            private void btnWav_Click(object sender, EventArgs e)
            {
                s.SetOutputToWaveFile(@"C:\io.wav");
                s.SpeakAsync(txtSubject.Text);  
            }
    
            private void btnSSML_Click(object sender, EventArgs e)
            {
                s.SpeakSsmlAsync(txtSubject.Text);
            }
        }
    }
    


    • Proposed as answer by Tamer Oz Monday, November 9, 2009 4:14 AM
    • Marked as answer by eryang Thursday, November 12, 2009 7:52 AM
    Saturday, November 7, 2009 3:12 PM
  •  Thank you Sir.... But that program shown 18 errors like this

    (Error    1    The name 'txtSubject' does not exist in the current context    
    Error    2    The name 'InitializeComponent' does not exist in the current context    
    Error    3    The name 'lblProgress' does not exist in the current context    
    Error    4    The name 'rbtnGenderAge' does not exist in the current context    
    Error    5    The name 'cmbGender' does not exist in the current context    
    Error    6    The name 'cmbAge' does not exist in the current context    
    Error    7    The name 'rbtnVoice' does not exist in the current context    
    Error    8    The name 'cmbVoice' does not exist in the current context    
    Error    9    The name 'txtSubject' does not exist in the current context    
    Error    10    The name 'lblProgress' does not exist in the current context    
    Error    11    The name 'lblState' does not exist in the current context    
    Error    12    The name 'cmbGender' does not exist in the current context    
    Error    13    The name 'cmbAge' does not exist in the current context    
    Error    14    The name 'cmbVoice' does not exist in the current context    
    Error    15    The name 'cmbVoice' does not exist in the current context    
    Error    16    The name 'lblVoiceProperties' does not exist in the current context
    Error    17    The name 'txtSubject' does not exist in the current context    
    Error    18    The name 'txtSubject' does not exist in the current context    
    )

      I dont know how to clear this errors in console application.. can you help me brother

       Thanks&Regards

            Dinesh

    Monday, May 21, 2012 6:26 AM
  • Hai Sir,

         I cleared that errors but i need Speech Recognition Application...

         My application have to type the text what the user speaks through mic..

         i have tried dictation for this but i cant get exact result.. please help for the same...

    Thanks&Regards

    Dinesh.K

    • Proposed as answer by ron dinkins Saturday, March 2, 2013 3:49 PM
    Monday, May 21, 2012 9:35 AM