I'm working on this project of speech recognition and text to speech. I got three scripts, one is the Form.cs, other is the script for the text to speech (Voice.cs) and another one for other methods Auxiliary.cs.
the Voice.cs has the variable SpeechSynthesizer synth = new SpeechSynthesizer(); as normal.
And then I have this void:
public void Say(string speech)
{
synth.SpeakAsync (speech);
}
When I call the Voice.Say(string) in the Form.cs script it works good, when I call it from the Auxiliary.cs it throws NullReferenceException in synth.
Why is this happening? I mean, the form script is calling it in the exact same way as the Auxiliary.cs
Sorry if this question already exists, I searched for it all over the site but yet, came up with nothing.
EDIT: These are the codes.
//Form1.cs
public partial class Form1 : Form
{
public Auxiliary auxiliary;
public Voice voice;
public void Form1_Load ()
{
voice = new Voice ();
auxiliary = new Auxiliary();
voice.Say("Hi, Patrick");
}
}
//Auxiliary.cs
public class Auxiliary
{
public Voice voice;
public void Start()
{
voice = new Voice();
voice.Say("Hi");
}
}
//Voice.cs
public class Voice
{
public SpeechSynthesizer synth;
public void Start()
{
synth = new SpeechSynthesizer();
}
public void Say(string speech)
{
synth.SpeakAsync(speech);
}
}