Codea Voice API Questions

Hi Codeans,

I’m writing a narrative engine for creating adventure games for the visually impaired and am protoyping this using the voice (text-to-speech) API…

It’s not quite working as I expected, I have tested with the code below and have added the outcomes as comments (note that my default language is ‘en-GB’):

    speech.language = "en-US"
    speech.say("Hello Simon") 
    -- Fast american female voice CORRECT

    local a = speech("Hello Simon")
    speech.say(a) 
    -- Normal English male voice, INCORRECT? 'en-US' value should be the inherited default?

    a = speech("Hello Simon")
    a.language = "en-US"
    speech.say(a) 
    -- Normal English male voice, INCORRECT? Expected 'en-US' explicit value

    speech.voice = speech.voices[1]
    a = speech("Hello Simon")
    speech.say(a) 
    -- Normal English male voice, INCORRECT? Expected default voice to be inherited?

    a = speech("Hello Simon")
    a.voice = speech.voices[1]
    speech.say(a) 
    -- Voice changed, CORRECT

So what I expected to be able to do was set the voice ‘per utterance’, as you can see from the last test I can set the utterance voice property, but I don’t really want to work with the voice table, I’d rather set the language explicitly…

I am guessing that certain parts of the underlying speech API are reset post-utterance, e.g. you cannot re-use an utterance (local var ‘a’ above) that has already been spoken…

Another question is the rate of speech, the en-US voice seems far too fast for sensible usage by default, are there default rates per voice?

Any enlightenment gratefully received…

Cheers,
Brookesi

Surely you can use a simple function and table to let you set voices by country, eg

countries={["US-Male"]="en-US", etc}

function Speak(text,country,sex)
    local a=speech(text)
    speech.language=countries[country.."-"..sex]
    speech.say(a) 
end

Hi @Ignatz,

The problem is, that just doesnt work, I tried this:

    function Speak(text,lang)
        local a = speech(text)
        speech.language = lang
        speech.say(a) 
    end
    
    Speak("Hello one", "en-US")
    Speak("Hello two", "en-IE")

It says the words using the default language only…

This is my point, as per my tests above, the API doesn’t seem to work consistently… I can set the ‘voice’ on a local utterance, but not language…

Brookesi