My goal is to translate text into sounds and videos according to sound files and video material. I splitted the text into words but I just could not figure out how to correctly search for my words in the text and say If (word==’ '), play this file. I know the code is incomplete, but I hope it will show what I want to do. I could only find out how to play the file if it contains a specific word. So in a nutshell: what I need is to play files one after another in the order of my text. Could somebody help me out?
Many thanks in advance!
if you have a String text split it with the String words[] = split(text,' ') so it turns the text into an array of strings, separated by spaces. So a string hello! today is a nice day! Will be split into {"hello!","today","is","a","nice","day!"} Now just create a function that removes all of the extra things like !?.,-_;:=)(/&%$#"! ... and return just the word. After that just loop and check for documented words (words with audio files)
The purify function I wrote (to get rid of extra symbols)
Code
char acceptable[] = ("aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789").toCharArray();
void setup() {
println(purify("He!!oT&!$\\/\\/ () |\\| `|` $|-|()\\/\\/! i used come characters to create a text out of symbols. After they are purified they won't show"));
}
void draw() {
}
String purify(String input) {
String newString = "";
for(int i = 0; i < input.length(); i++) {
for(int j = 0; j < acceptable.length; j++) {
if(input.charAt(i) == acceptable[j]) {
newString += acceptable[j];
break;
}
}
}
return newString;
}
shortened code:
Short code
char acceptable[] = ("aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789").toCharArray();
String purify(String input) {
String newString = "";
for (int i = 0; i < input.length(); i++) for (int j = 0; j < acceptable.length; j++) if (input.charAt(i) == acceptable[j]) {
newString += acceptable[j];
break;
}
return newString;
}