Hello, I have been experimenting a bit. And I was wondering how I could make my own “text to speech”.
The way it works is, there is a library of audio files representing a word. When the user inputs text, the string will get split, and check to see if the word is in the database. If it is, it will match up the word with the name of the audio clip. If not, it will skip it.
I got everything to work. Though when it comes to actually playing the sound… That is where the issue comes in.
I tried to loop through the list of words, and set a bool based on whether or not the Audio Source is finished playing. This bool is called “canSpeak”. The audio source would get the audio clip applied, and if it “could Speak” then it would play it.
The problem is, it won’t wait for the clip. It won’t change the clip in the audio source (unless it’s just too fast). And most of all. It skips to the last word. And only plays that. So if I type in “hi my name is bob”… it will just say “bob”.
This is my code.
public void ParseText()
{
tiString = ti.text.ToLower();
string[] st;
st = tiString.Split(' ');
for (int i = 0; i < wd.words.Count -1; i++)
{
if (wd.words.Contains(st[i]))
{
aus.clip = wd.sounds[i];
aus.Play();
Debug.Log("Word: <color=yellow>" + st[i] + "</color> <color=green>is valid.</color>");
}
else
{
Debug.Log("Word: <color=yellow>" + st[i] + "</color> <color=red>is not valid.</color>");
}
}
}
Is there something I am doing wrong? I have been playing with this for hours now and can’t figure it out