Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 5 different voices installed in my system

Alberto16
Audrey16
IVONA Amy
Microsoft Sam
VM Kate

when I run the following test app both Alberto16 and Audrey16 do not fire the "speechinprogress" event. All the other voices fire the event. Could this be a bug in the speech API.

C#
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 EventhandlerProblem
{
    public partial class Form1 : Form
    {

        SpeechSynthesizer synth = new SpeechSynthesizer();
        PromptBuilder pb = new PromptBuilder();
        String[] installedVoices = new String[10];
        
        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            //gets all installed  voices and displays them in the listbox
            foreach (InstalledVoice voice in synth.GetInstalledVoices())
            {
                comboBox1.Items.Add(voice.VoiceInfo.Name);
                System.Console.WriteLine(voice.VoiceInfo.Name);
            }

            synth.SpeakProgress += new EventHandler<speakprogresseventargs>(synth_SpeakProgress);
        }

        void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
        {
            System.Console.WriteLine("speech in progress");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            pb.ClearContent();
            pb.AppendText("This is a test");
            synth.Speak(pb);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            synth.SelectVoice(comboBox1.Text);
        }
    }
}
Posted
Updated 3-Dec-11 1:40am
v6
Comments
Sergey Alexandrovich Kryukov 25-Nov-11 19:39pm    
OK, looks good but what do you do next? Did you synthesize speech later on. If you don't nothing happens. :-)
I understand, naive question, but let's sort it out. Also, could you make a complete one-file code sample, which is minimal to compile and show the problem? Post it using "Improve question", but format the code propertly... I'll show how.
--SA
Sergey Alexandrovich Kryukov 25-Nov-11 19:41pm    
Code format fixed. When using "Improve question" pay attention for it, do the same. Don't forget to escape <>.
--SA
Richard MacCutchan 3-Dec-11 7:41am    
Really fixed the code formatting, and added <pre> tags.
DaveAuld 4-Dec-11 4:58am    
I copied your code across to a fresh C# project added the necessary Speech library reference noted that the compiler didn't like your event Handler. It should have been synth.SpeakProgress += new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress); (Note the Capitals). I only have one voice installed, and it worked fine, and Microsoft Anna, spoke away quite happily and thh speech in progress event fired.

The only thing i can think is maybe the Speech isn't finished by the time the next one starts and is maybe blocking an event. You should add the event handler for the SpeechCompleted and use use that to prevent the next one starting until that has fired. Give that a go and see if it makes a difference.

1 solution

Thx Dave!

I have tried back and forth with the 5 voices installed. the behavior is clear. Only those 2 voices don't work. I have just added some more eventhandlers and one more voice to my system. Now there is even more chaotic behavior. All voices fire the "speech started" event. No voice fires the "speech ended" event. None of the 16bit voices and the spanish voices fire the speech in "progress event" it really looks like a bug in the speech API. here is the code I added to the previous project.

XML
synth.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(synth_SpeakCompleted);
    synth.SpeakStarted += new EventHandler<SpeakStartedEventArgs>(synth_SpeakStarted);
    synth.BookmarkReached += new EventHandler<BookmarkReachedEventArgs>(synth_BookmarkReached);
}

void synth_BookmarkReached(object sender, BookmarkReachedEventArgs e)
{
    System.Console.WriteLine("bookmark reached");
}

void synth_SpeakStarted(object sender, SpeakStartedEventArgs e)
{
    System.Console.WriteLine("speech has started");
}

void synth_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
    System.Console.WriteLine("speech is completed");
}
 
Share this answer
 

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