Using Talkie library with Array(s) of Words - can this be done?

Hi all! First time post. I’m using an Arduino Nano ATmega328p (old bootloader) with speaker (headphones) connected to pin 3 and ground. No other connections, power from pc usb.

I found the Talkie library and I’m trying to create a Magic 8 Ball like application with audible responses. I want to store the responses in arrays so that I can randomly select a response and then have a function loop through each word (as of now there would be a function for each array).

While I was testing whether I could use array values for voice.say() I initially had some success with the second through nth word playing correctly, but the first word would be gibberish. This was using explicit values for the elements (i.e. voice.say(phrase01[0]); voice.say(phrase01[1])…). After working on things for a while now all I get is (audible) gibberish even for the explicit calls.

I’m wondering if I can even do what I’m trying to - feeding an array value to voice.say() (my initial testing was promising, but not any longer). In the attached code, playPhrase01() generates gibberish and playPhrase02() gives expected values. DigitalWrites to pin3 are in place to prevent noise between phrases.

Any help would be appreciated!

Thanks.

#include <Arduino.h>

#include "Talkie.h"
#include "Vocab_US_Large.h"
#include "Vocab_US_Acorn.h"

Talkie voice;

uint8_t phrase01[] = {sp2_A, sp3_MILLION, sp4_TO, sp3_ONE};
// byte phrase01[] = {sp2_A, sp3_MILLION, sp4_TO, sp3_ONE};

uint8_t phrase02[] = {sp4_THE, sp3_ANSWER, sp4_IS, spa_YES};

uint8_t phrase03[] = {sp4_ROGER, spa_THAT};

uint8_t phrase04[] = {sp4_EXPECT, sp4_FAILURE};



void setup() {
pinMode(3, OUTPUT);
digitalWrite(3,HIGH);

Serial.begin(9600);
// Serial.println(myelements);

delay(1000);

//    voice.doNotUseUseInvertedOutput();
#if defined(CORE_TEENSY)
    pinMode(5, OUTPUT);
    digitalWrite(5, HIGH); //Enable Amplified PROP shield
#endif

   /*
    voice.say(sp3_VISIBILITY);
    voice.say(sp3_OBSCURED);
    digitalWrite(3,HIGH);
    delay(500);
    */
    voice.say(sp4_HAVE);
    voice.say(sp2_A);
    voice.say(sp4_GREAT);
    voice.say(sp2_TIME);
    digitalWrite(3,HIGH);
    delay(500);
    
    voice.say(phrase01[0]); // initially this was playing gibberish for first value and the individual words for [1]-[3]
    voice.say(phrase01[1]);
    voice.say(phrase01[2]);
    voice.say(phrase01[3]);
    digitalWrite(3,HIGH);
    
    playPhrase01();
    delay(500);
    playPhrase02();
}

void loop() {
}

void playPhrase01() {
    int myelements = sizeof(phrase01)/sizeof(phrase01[0]);
    for (int rowCount = 0; rowCount < myelements; rowCount++) {
      voice.say(phrase01[rowCount]);
      digitalWrite(3,HIGH);
      delay(125);
      Serial.println(rowCount);
    }
}    
void playPhrase02() {
    voice.say(sp4_THE);
    voice.say(sp3_ANSWER);
    voice.say(sp4_IS);
    voice.say(spa_YES);
    digitalWrite(3,HIGH);
}

I looked at the talkie library. The say method takes a uint8_t* as a parameter.

If you change all of your uint8_t arrays to uint8_t* arrays I think that will solve your problem but I cannot test it.

Like this:

uint8_t* phrase01[] = {sp2_A, sp3_MILLION, sp4_TO, sp3_ONE};

Those "words" are not of type 'uint8_t' but an array of those so your array declaration is wrong. Something like sp3_MILLION is a 'const char *' so that is the type to use for your arrays. You are creating an array of arrays.

Note: they also use PROGMEM so they are stored in program space, so you might need to do something special to deal with them properly.

Changing the array definitions to use uint8_t* as the type was enough to get things working. Thanks so much!