Search code examples
c++tizen-native-app

Read text multiple times with Elementary access on native Tizen TV


Hello fellow programmers,

I am trying to use the Text To Speech functionality provided by the Elementary access library (from Enlightenment) in a native app for tizen TV.

So far I have been able to read text, but only once: when I call the API multiple times, only the first call is rendered to audio. I have investigated the sources of elementary access, but can't really spot the problem.

Here is a sample of my app:

#include <app.h>
#include <Elementary.h>

#include <unistd.h>
#include <string>

using namespace std;

const char APP_PKG[] = "org.tizen.tts";

/// Struct to store application information and passed at start time to the efl framework
struct _appdata
{
    const char *name; 
    Evas_Object *win; 
};


static bool
_create(void *data)
{
    elm_config_access_set(EINA_TRUE);
    return true;
}

static bool
_control(app_control_h app_control, void *data)
{
    for (int i = 1; i <= 2; i++) {
        string text = to_string(i) + ". Read me please.";
        elm_access_say(text.c_str());
        // sleep(10);
    }
    return true;
}

int
main(int argc, char *argv[])
{
    _appdata ad = {0,};
    ad.name = APP_PKG;

    ui_app_lifecycle_callback_s lifecycle_callback = {0,};

    lifecycle_callback.create = _create;
    lifecycle_callback.app_control = _control;

    return ui_app_main(argc, argv, &lifecycle_callback, &ad);
}

I have tried using elm_access_force_say, also moving elm_config_access_set(EINA_TRUE) inside the loop, but everytime the sentence is only said once.

Here in the source is some code called by elm_access_say. It seems that the api makes a call to espeak executable, strangely I can't find any espeak executable on the device.

Tizen provides an API for using the TTS engine in native apps, but only for mobile and watches (at least in the documentation).

If someone ever tried to use the TTS engine on native TV, or have more experience with the Elementary access library, and would like to share some knowledge, I would be really thankful.


Solution

  • If you are using Tizen 4.0 or above and you want to read text multiple times using accessibility framework, please use the elm_atspi_bridge_utils_say. Below code snippet demonstrates how to read consecutive numbers.

    statc void reade_n_times(int n) {
    char buf[32];
    for (int i=1;i<=n;++i){
     snprintf(bug,sizesizeof(buf), "%d", i);
       elm_atspi_bridge_utils_say(buf, EINA_FALSE, say_cb, NULL);
              }
       }  
    

    Full specification of elm_atspi_bridge_utils_say can be found here: https://developer.tizen.org/dev-guide/tizen-iot-headed/4.0/group__Elm__Atspi__Bridge.html#gafde6945c1451cb8752c67f2aa871d12d "