Page Example

Voice Control Elm Sample Overview

Mobile native

The Voice Control for EFL Components application demonstrates how you can register voice commands for EFL-supported UI components. The voice commands allow the user to interact with visible UI components inside the application with their voice. The Voice Control elementary library recognizes spoken commands from registered UI components.

You do not need to consider how to recognize voice commands or start and stop the recognition process. A preloaded voice recognition application handles the process automatically. You only need to set the command and hint on every EFL elementary component on which you want to use the voice command.

The following figure illustrates the main view of the Voice Control for EFL Components. On the right side, the application screen has the Voice Control elementary features enabled. When the screen is updated, any UI components that have a registered command and hint are shown with a voice tooltip (hint). When the user speaks the hint, the callback function related to the UI component is executed.

Figure: Application view

Application view Application view

Implementation

To implement the Voice Control elementary application:

  1. Create the layout for the application.

    For this sample application, the applied native components include a button, checkbox, genlist, toolbar, and slider. The appdata_s structure and some global values have information for implementing those components. This sample concentrates on how to use the Voice Control elementary; for more information on native UI component usage, see the UI Components sample.

  2. Include the <voice_control_elm.h> header file in your application:
    #include <voice_control_elm.h>
    
  3. Initialize the Voice Control elementary library with the vc_elm_initialize() function:
    static bool 
    app_create(void *data)
    {
       int ret;
       ret = vc_elm_initialize();
       if (VC_ELM_ERROR_NONE != ret)
       {
          // Error handling
       }
    }
    
  4. Create a handle for each UI component for which you want to set a command and hint. Use the vc_elm_create_object() function to create a handle for Evas_Objects, and the vc_elm_create_item() function for Elm_Object_Items.
    static vc_elm_h first_view[7];
    static vc_elm_h tabbar_view[2];
    
    static Evas_Object*
    create_basic(appdata_s *ad)
    {
       int ret;
       Evas_Object *button; 
    	
       // Creating Evas_Object button
       button = elm_button_add(ad>>win);
       ret = vc_elm_create_object(button, &first_view[0]);
       if (VC_ELM_ERROR_NONE != ret) 
       {
          // Error handling
       }
    }
    
    static Evas_Object*
    create_toolbar(appdata_s *ad)
    {
       int ret;
       Evas_Object *toolbar;
       Elm_Object_Item *it;
    
       // Creating Elm_Object_Item toolbar
       toolbar = elm_toolbar_add(ad->nf);
       it = elm_toolbar_item_append(toolbar, NULL, "First", toolbar_it_cb, ad);
       ret = vc_elm_create_item(it, &tabbar_view[0]);
       if (VC_ELM_ERROR_NONE != ret) 
       {
          // Error handling
       }
    }
    
  5. Use the handle created for a specific UI component to set a command the user must speak to perform actions on the UI component:
    static vc_elm_h first_view[7];
    static vc_elm_h tabbar_view[2];
    
    static Evas_Object*
    create_basic(appdata_s *ad)
    {
       Evas_Object *button; 
    	
       // Creating Evas_Object button
       button = elm_button_add(ad->win);
       vc_elm_create_object(button, &first_view[0]);
       vc_elm_set_command(first_view[0], &first_view_cmd[0]);
    
    
  6. To show the command on the screen as a tooltip, set a hint (tooltip) for the UI component:
       vc_elm_set_command_hint(first_view[0], &first_view_cmd[0]);
    
  7. Set the hint direction and offset (X and Y coordinates).

    By default, the hint tooltip is shown so that it does not cover the underlying UI component and does not intersect with other hints.

       vc_elm_set_command_hint_direction(first_view[0], VC_ELM_DIRECTION_CENTER);
    }
    
  8. When voice control is no longer needed, destroy the handle and deinitialize the library:
    static void 
    nf_back_cb(void *data, Evas_Object *obj, void *event_info)
    {
       int index;
    
       for (index = 0; index < 7; ++index);
          vc_elm_destroy(first_view[index]);
    }
    
    static void 
    app_terminate(void *data) 
    {
       vc_elm_deinitialize();
    }