I receive single words form a microphone input that I will like to save in a text file.
I manage to save one word in the text file, but when i say a new word the old one get overwritten.
How can I add the new word after the one(s) already been saved?
With saveFrame() you can specify the name of the sequence with the filename parameter, including hash marks (####), which will be replaced by the current frameCount value. (The number of hash marks is used to determine how many digits to include in the file names.)
But you can do this if you do not what to overwrite your file
int name=0;
void draw()
{
String words = "apple bear cat dog";
String[] list = split(words, ' ');
// Writes the strings to a file, each on a separate line
saveStrings("nouns-"+str(name++)+".txt", list);
}
Thank you for explaining that, I tried but what he did is creating another file named H-Farm######.txt in the data folder of the sketch and the behavior is the same, it jusr write one word and keep overwriting it.
I try now with the suggestion you give me! Thank you
I’m sorry, but is not clear to me in the exemple you give me where exactly do I declare in witch text file the code should save the word(s).
In the way I show below it dose not work.
int name=0;
void webSocketServerEvent(String msg) {
String[] wordFile = split(msg, ' ');
saveStrings("nouns-"+"MyText"+".txt", wordFile); // Writes the strings to a file, each on a separate line
this will give you a list of file like:
nouns-0.txt
nouns-1.txt
nouns-2.txt
nouns-3.txt
nouns-4.txt
nouns-5.txt
nouns-6.txt
nouns-7.txt
nouns-8.txt
nouns-9.txt
nouns-10.txt
Ah wait, maybe i wrote something that was misleading.
I don’t want to create multiple text files. What I would like to get is only one text file with a list of the words that has been recorder from the microphone.
sorry about that
what happen now with the code is that i save: “Funny” and then when I save “Blue” it overwrite the word funny instead of having something like:
Funny
Blue
sorry, i think that the point here might be
-a- first need to read the already existing strings from the file
-b- then need to extend that array
-c- then need to add the new word from the new split array one by one
-d- and write all to the same file again.
? is that the function what you need?
Hi kll, yes you get it right to the point.
I’m not able to do it by my own as I’m a beginner. Could you please provide me some documentation or
example on how i could build such a function?
Thank you
String filename ="data/MyText.txt";
String[] lines;
lines = loadStrings(filename);
String[] newlines = split(answer, ' ');
for ( String l : newlines ) {
expand(lines);
lines = append(lines, l); // add one line for each new word
}
saveStrings(filename, lines);
yes that definitely looks promising and more suitable for my needs. Thanks a lot.
I will integrate it in my code and test it. I will let you know the result.
but i just read what you actually try to do, the word-cloud thing?
so you should first loop through the “existing” list and check if the word is there already?
and only if NOT add it?
Hey, first of all thank you al lotfor your help, now it works perfect.
Yes i’m try to do the word-cloud.
Actually the text at the beginning is empty (no word) then people can speak to the microphone and the word they say will be displayed. The more the same word has been say then bigger it will appear.
I’m editing a code i’ve found online and i’m struggling to understand how it works. Originally it upload a text, he count the words and display the cloud.
I need that he start from 0 words and then start adding them and resize them live, while running