speakjet voicebox shield programming question

Ok, I HOPE there is a simple fix to this:

I have a sketch that will send a word to the speakjet (voice synthesizer) and it will say the word, in the sketch I have a massive list of arrays for e.g.

char alien[] = {7,127,7,154,145,128,8,7,133,141};

....

char zebra[] = {167,7,128,170,7,148,134};

You get the idea.

It works when I upload a sketch with the following:

speakjet.print(zebra);

Now I want to have an array of words such as:

char* rdmWords[]={"alien","zebra"};

pick a random word:

x = rdmWords[random(2)];

Then get the speakjet to say it:

stringOne.toCharArray(z, 6);

speakjet.print(z);

Now that last bit doesn't wok! >:( >:(

If anyone could help me, I would muchly appreciate it, I hope it can be achieved! Also an explanation as to why it doesnt work would also be great.

Thank-you, I hope that was clear for y'all.

Now that last bit doesn't wok!

Try a different method of cooking.

What does "does not wok" mean? Does not compile? Results in the wrong value being selected? Says "Alien" when it should say "Potato"?

Since rdmWords is an array of pointers to char, and x is of unknown type, and completely unrelated to stringOne, and who knows what z is, or how big it is if it is the right type, no one can help you.

PaulS:
Since rdmWords is an array of pointers to char, and x is of unknown type, and completely unrelated to stringOne, and who knows what z is, or how big it is if it is the right type, no one can help you.

haha, fair enough.

its:

char* x; // gets the random word from char* array of words
char z[10]; //is the buffer char purely for the "toCharArray" function

Im basically converting a string into a char so the speakjet will say the random word.

So if I have in the script:

speakjet.print(alien);

it will spit out alien, however if I get the word "alien" from an array of words (char* rdmWords[]....) and then convert it into a char array (z[10]):

speakjet.print(z);

It doesnt actually say anything!

if I go:

Serial.println(z);

I get alien or whatever word printing out on the serial port, so that is why I am stumped.

Well thanks for your time, I hope I explained correctly, I'm still bit of a noob, hopefully your a genius

Im basically converting a string into a char

No, you are not. You are uselessly converting a string (a NULL terminated array of chars pointed to by a pointer) to a String, and then converting the String to a string. Stop that crap.

Try this:

char *alien = { /* whatever needs to go here */ };

char *ptr = alien;

speakjet.print(alien);

speakjet.print(ptr);

Does the device say "Alien" both times? If so, then when you create the array of pointers, and select one randomly, simply make ptr point to the selected word, and make speakjet say the word pointed to be the pointer.

whaaat!? OK that was impressive, yes it worked!

an array of pointers you say? is that like my char* words[] = {blah blah blah} or is it something else?

And thank-you, you are truly a master.

also, could you point to a line in the sketch? because that way I could just get a random number making everything very easy, but I know it's never that simple

is that like my char* words[] = {blah blah blah}

If blah, blah, and blah are arrays, yes.

char *rdmWords[]={alien, zebra};

also, could you point to a line in the sketch?

No.

because that way I could just get a random number making everything very easy, but I know it's never that simple

But, it is.

int rndNum = random(0, 2);
char *wordToSay = rdmWords[rndNum];
speakjet.print(wordToSay);

PaulS, i've been away the past few days, I took my laptop and the arduino with me, so I'm gonna have a go at what you have just said tomorrow when I get a spare couple of hours.

Thanks for the help, you might be my new best friend at the moment, I'll let you know how it goes!

I really do appreciate the help mate, keep up the good work!