Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all,

I am creating a application in which i want to enter text in a text box and after that by clicking on button it will speak out what i have entered in textbox,..

it is working but it only sounds like plah-plah...

following is the code:-

C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Speech.Synthesis;

namespace ItSpeaks
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private SpeechSynthesizer speech;
        public MainWindow()
        {
            this.InitializeComponent();
            speech= new SpeechSynthesizer();

            // Insert code required on object creation below this point.
        }

        private void Speak(object sender, System.Windows.RoutedEventArgs e)
        {
            speech.SpeakAsync(textToSpeak.Text);
            speech.Volume = 100;
            speech.Rate = -2;
            // TODO: Add event handler implementation here.
        }
    }
}
Posted

1 solution

This probably happens since the output voice language does not match your text. Try it out with a different output voice. Here is how you can get a list of all installed voices:
C#
System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Synthesis.InstalledVoice> tmp = speech.GetInstalledVoices();
foreach (object MyVoice in tmp)
{
  comboBox1.Items.Add((MyVoice as System.Speech.Synthesis.InstalledVoice).VoiceInfo.Name);
}

If no voice matches, you may want to install a new voice.
 
Share this answer
 
Comments
abhishekagrwl25 22-May-12 3:28am    
done this...now it is showing 3 items in combolist:-
1) MicrosoftMike
2) MicrosoftMary
3) SampleTTSVoice

now what to do to set the voice..??
JF2015 22-May-12 3:46am    
speech.SelectVoice(comboBox1.SelectedItem.ToString());
abhishekagrwl25 22-May-12 4:09am    
done this. now it shows exception:-
Cannot set voice. No matching voice is installed or the voice was disabled.

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