THE ONE OF IoT,YOUR ONLY CHOICE!
TTS - Text To Speech
 

TTS


TTS Listner is one of Infairy broadcast channel which can let all developer receive the voice command from end users. Which means the event bundle can own a voice control ability, just listen the TTS broadcast and analysis the incoming keyword, easy to be a voice control app.

When user made a voice command from Infairy App, Infairy will make a voice recognization and pass through 5 keyword sentences to all bundles in the Infairy.

Developer can listen TTS broadcast channel to get all event by implement "EventTTSDNA" class, please follow the step as below:

First, import package as follows:
        import org.osgi.service.event.Event;
        import org.osgi.service.event.EventHandler;
        import com.infairy.cocina.SDK.gene.EventTTSDNA;
      
then, implement "EventHandler" in your bundle class:
        package yourBundle;

        public class CommData implements BundleActivator, EventHandler{
            ....

        }
      
Third, implement HandleEvent() method,
        public void handleEvent(Event evnt) {
          ...
        }
      
Last, do not forget listen TTS broadcast channel in start() method,
        package yourBundle;

        public class CommData implements BundleActivator, EventHandler{
            ....

            public void start(BundleContext context) throws Exception {

                ...
                device.ListenBroadcast(context, this, device.BROADCAST_CHANNEL_TTS);

            }

        }
      
after done the process as above, you can get the event from all other sensor:
          public void handleEvent(Event evnt) {
            if(evnt==null) return;

            //Cast event object from the property of BROADCAST_TTS_VOICE_TRIGGER_EVENTOBJECT to EventTTSDNA 
            EventTTSDNA eto=(EventTTSDNA)evnt.getProperty(device.BROADCAST_TTS_VOICE_TRIGGER_EVENTOBJECT );
            if(eto==null) return;

            //get the voice to speech keyword array
            String VR[]=eto.WORDS;//(String[]) evnt.getProperty(device.BROADCAST_TTS_VOICE_WORDS);
            
            //Analysis each keyword and find any concern with your bundle
            for(int i=0; VR!=null && i < VR.length; i++){

              //isPinYinOf() fucntion same as indexOf(), which use chinese pinyin to make the position of the keyword assigned
              if(device.isInPinYinOf(VR[i],LanguagePack("天气"))!=-1 && device.isInPinYinOf(VR[i],LanguagePack("预报"))!=-1){
                if(device.isInPinYinOf(VR[i],LanguagePack("今天晚上"))!=-1){
                   .....
                }
              }
            }
          }

      
The EventTTSDNA interface shows as below:
          /**
           * Voice recognition words array(5 words)
           */
          public String[] WORDS=null;
          /**
           * the number in the Voice recognition words, default is -1
           */
          public int NUMBER=-1;
          /**
           * the hour number in the Voice recognition words, default is -1 
           */
          public int HOUR=-1;
          /**
           * the minute number in the Voice recognition words, default is -1 
           */
          public int MINUTE=-1;
          /**
           * the latitude where from the user's geo-position 
           */
          public String LATITUDE="";
          /**
           * the longitude where from the user's geo-position 
           */
          public String LONGITUDE="";
          /**
           * 
           * the ID of WORD from, defined by developer
           */
          public  String FROM_ID=""; 
          /**
           * selected index by multiple choose
           */
          public String SELECTED_INDEX="";
          
          /**
           * Define the branc ID of Voice come from. 
           */
          public String BranchID="";