Ticket #705: pocketsphinx.diff

File pocketsphinx.diff, 2.6 KB (added by tegzed, 9 years ago)

call dbus-send directly from pocketsphinx_continuous to eliminate the need for intermediate forwarding script

  • continuous.c

     
    5353
    5454#include <stdio.h>
    5555#include <string.h>
     56#include <stdlib.h>
    5657
    5758#if !defined(_WIN32_WCE)
    5859#include <signal.h>
     
    7172
    7273#include "pocketsphinx.h"
    7374
     75char* navit_get_cmd(char*word);
     76
    7477static const arg_t cont_args_def[] = {
    7578    POCKETSPHINX_OPTIONS,
    7679    /* Argument file. */
     
    319322        printf("%s: %s\n", uttid, hyp);
    320323        fflush(stdout);
    321324
     325        char str[512]  = "";
     326        char str2[512] = "";
     327        int word_cnt=0;
     328        char*tok;
     329        while(tok=strtok((word_cnt==0)?hyp:NULL, " \t\n")) {
     330          strcat(str2,(navit_get_cmd(tok)==NULL)?"":navit_get_cmd(tok));
     331          strcat(str2," ");
     332          ++word_cnt;
     333        }
     334
     335        sprintf(str,"/usr/bin/dbus-send --print-reply --dest=org.navit_project.navit /org/navit_project/navit/default_navit org.navit_project.navit.navit.add_voice_data string:'%s '",str2);
     336        system(str);
     337        printf("CMD %s\n",str);
     338
    322339        /* Exit if the first word spoken was GOODBYE */
    323340        if (hyp) {
    324341            sscanf(hyp, "%s", word);
     
    342359    longjmp(jbuf, 1);
    343360}
    344361
     362int  navit_word_map_size;
     363typedef char* charptr;
     364typedef charptr navit_word_map_item[2];
     365navit_word_map_item* navit_word_map;
     366
     367/*
     368 * get replacement word from word map
     369 */
     370char* navit_get_cmd(char*word)
     371{
     372  int i;
     373  for(i=0;i<navit_word_map_size;++i) {
     374    if(!strcmp(navit_word_map[i][1],word)) {
     375      return navit_word_map[i][0];
     376    }
     377  }
     378  return NULL;
     379}
     380
     381/*
     382 * load word mapping to enable user to use her/his own command set
     383 */
     384void load_navit_word_map()
     385{
     386  navit_word_map_size = 0;
     387  navit_word_map = NULL;
     388  FILE*fp;
     389  char* fn = "navit_voice_command_map.txt";
     390  if((fp=fopen(fn,"rt"))) {
     391    while(!feof(fp)) {
     392      char str[128];
     393      if(fgets(str,127,fp)) {
     394        char*tok1 = strtok(str," \t\n");
     395        char*tok2 = strtok(NULL," \t\n");
     396        if(tok1 && tok2) {
     397          navit_word_map = realloc(navit_word_map,sizeof(navit_word_map_item)*(navit_word_map_size+1));
     398          navit_word_map[navit_word_map_size][0]=strdup(tok1);
     399          navit_word_map[navit_word_map_size][1]=strdup(tok2);
     400          ++navit_word_map_size; 
     401        }
     402      }
     403    }
     404  }
     405  fclose(fp);
     406}
     407
    345408int
    346409main(int argc, char *argv[])
    347410{
    348411    char const *cfg;
    349412
     413    load_navit_word_map();
     414
    350415    /* Make sure we exit cleanly (needed for profiling among other things) */
    351416    /* Signals seem to be broken in arm-wince-pe. */
    352417#if !defined(GNUWINCE) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)