Referencing Speech synthesis in page load but still getting NullReferenceException

49 views Asked by At

The problem was that when I click the button, it reads the text but even after it is finished, the page is still waiting for localhost, so I thought maybe I should instantiate the reader on page load only as I did in the code below, getting a NullReferenceException

protected void Page_Load(object sender, EventArgs e)
{
        if (!IsPostBack)
        {
            Label1.Text = "click button";
            reader = new SpeechSynthesizer();
        }
        else
        {}
}

protected void Button1_Click(object sender, EventArgs e)
{
          reader.SpeakAsync(TextBox1.Text);//getting the error here
            Label1.Text = "SPEAKING";
}
0

There are 0 answers