コード例 #1
0
ファイル: phoenix_serv.c プロジェクト: 10v/cmusphinx
/*-----------------------------------------------------------------------*
 * Main routine which takes a string as input and returns a parse string * 
 *-----------------------------------------------------------------------*/
Gal_Frame send_to_parse(Gal_Frame f, void *server_data)
{
   int i, path_score;
   char *in_string, *out_string, *sysid;
   Gal_Frame f_new = Gal_MakeFrame("main", GAL_CLAUSE);

   /* get the input string to parse from the key's value */
   in_string  = Gal_GetString(f, ":input_string");
   sysid      = Gal_GetString(f, ":sysid");
   path_score = Gal_GetInt(f, ":path_score");

   if (in_string == NULL)
      in_string = Gal_GetString(f, ":parse_input");

   /* strip out punctuation, comments, etc, to uppercase */
   strip_line(in_string);

   /* Call Phoenix Parse function */
   parse(in_string, gram);

   /* print parses to buffer */
   if( num_parses > MaxParses ) num_parses= MaxParses;
   if( num_parses < 1 ) { strcpy(outbuf, "No Parse"); }
   else {
	out_string= outbuf;
	for(i= 0; i < num_parses; i++ ) {
	    sprintf(out_string, "PARSE_%d:\n", i);
	    out_string += strlen(out_string);
	    print_parse(i, out_string, extract, gram);
	    out_string += strlen(out_string);
	    sprintf(out_string, "END_PARSE\n");
	    out_string += strlen(out_string);
	}
	sprintf(out_string, "\n");
	out_string= outbuf;
   }

   /* clear parser temps */
   reset(num_nets);

   /*  create a new frame containing the parse */ 
   Gal_SetProp(f_new, ":parse_input", Gal_StringObject(in_string));
   Gal_SetProp(f_new, ":parse_output", Gal_StringObject(outbuf));
   if (sysid != NULL) Gal_SetProp(f_new, ":sysid", Gal_StringObject(sysid));
   if (path_score != 0) Gal_SetProp(f_new, ":path_score", Gal_IntObject(path_score));

   /* write parse output frame to HUB */
   GalSS_EnvWriteFrame((GalSS_Environment *) server_data, f_new, 0);

   return(f);
}
コード例 #2
0
ファイル: external_api.c プロジェクト: junion/GalaxyWinPython
void GalHUB_SetHubDefaultDomain(HUB *hub, char *domain, char *domain_key)
{
  if (hub->default_domain_key) {
    free(hub->default_domain_key);
  }  
  hub->default_domain_key = _gal_strdup(domain_key);
  Gal_SetProp(hub->globals, domain_key, Gal_StringObject(domain));
}
コード例 #3
0
ファイル: external_api.c プロジェクト: junion/GalaxyWinPython
void GalHUB_SetHubUserID(HUB *hub, char *user_id, char *user_id_key)
{
  if (hub->user_id_key) {
    Gal_DelProp(hub->globals, user_id_key);
    free(hub->user_id_key);
  }
  hub->user_id_key = _gal_strdup(user_id_key);
  Gal_SetProp(hub->globals, user_id_key, Gal_StringObject(user_id));
}
コード例 #4
0
Gal_Frame hub_debug_prompt(Gal_Frame frame, void *server_data)
{ 
  Gal_Frame reply_frame = Gal_MakeFrame("hub_debug_cmd", GAL_CLAUSE);
  int buf_size = 256;
  char cmd[buf_size];
  char *help_msg = "C: disable debug and continue\nc: continue\nd: session DB\ne: exit Hub\ng: globals\nh: help\nl: locks\nm: message\nr: server\ns: session\nt: token\n";

  /* Get the debug command. */
  printf("%s", help_msg);
  printf("--> ");
  fflush(stdout);
  fgets(cmd, buf_size, stdin);

  Gal_SetProp(reply_frame, ":debug_cmd", Gal_StringObject(cmd));
  return reply_frame;
}
コード例 #5
0
ファイル: Audio.c プロジェクト: junion/GalaxyWinPython
static void __AudioPoll(AudioDevice *a, void *data, int num_samples)
{
  AudioPkg *p = (AudioPkg *) a->client_data;
  Gal_Frame output_f;

  printf("[Previous device state is %s.]\n[Current device state is %s.]\n",
	 AudioDeviceStateName(a->previous_device_state),
	 AudioDeviceStateName(a->current_device_state));
  fflush(stdout);
  
  switch (a->current_device_state) {
  case AUDIO_IDLE:
    switch (a->previous_device_state) {
    case AUDIO_RECORDING:
      /* We have data and this is the last chunk. */
      if (!p->out_proxy) {
	GalUtil_Warn("No out proxy to send audio");
      } else {
	GalSS_ProxyArrayAdd(p->out_proxy, data, num_samples);
	printf("[Audio data from user (%d samples).]\n", num_samples);
	fflush(stdout);
	GalSS_ProxyDone(p->out_proxy);
	GalSS_FreeBrokerProxy(p->out_proxy);
	p->out_proxy = (GalSS_BrokerProxy *) NULL;
	printf("[Audio data from user done.]\n");
	fflush(stdout);
      }
      break;
    }
    break;
  case AUDIO_RECORDING:
    switch (a->previous_device_state) {
    case AUDIO_IDLE:
      /* We have data and this is the first chunk. */
      if (p->out_proxy) {
	GalUtil_Warn("Out proxy already exists");
      } else {
	output_f = Gal_MakeFrame("FromAudio", GAL_CLAUSE);	
	/* Set up the outgoing broker connection. */
	p->out_proxy = GalSS_ProxifyObjectType(p->env, GAL_INT_16, 0, 10);
	
	if (p->out_proxy) {
	  /* Send the first chunk. */
	  GalSS_ProxyArrayAdd(p->out_proxy, data, num_samples);
	  printf("[Audio data from user (%d samples).]\n", num_samples);
	  fflush(stdout);
	  /* Notify the Hub that data is coming. */
	  Gal_SetProp(output_f, ":sample_rate",
		      Gal_IntObject(a->sample_rate));
	  Gal_SetProp(output_f, ":encoding_format",
		      Gal_StringObject(a->encoding_format));
	  Gal_SetProp(output_f, ":proxy",
		      Gal_CreateProxyObject(p->out_proxy, 0));
	  GalSS_EnvWriteFrame(p->env, output_f, 0);	  
	}
	Gal_FreeFrame(output_f);
      }
      break;
    case AUDIO_RECORDING:
      /* We have data and this is an intermediate chunk. */
      if (!p->out_proxy) {
	GalUtil_Warn("No out proxy to send audio");
      } else {
	GalSS_ProxyArrayAdd(p->out_proxy, data, num_samples);
	printf("[Audio data from user (%d samples).]\n", num_samples);
	fflush(stdout);
      }
      break;
    }
    break;
  case AUDIO_PLAYING:
    break;
  case AUDIO_UNAVAILABLE:
    /* The device shut down. End the session and exit. */
    /* We ran out of inputs. Disconnect. */
    printf("Audio no longer available. Disconnecting.\n");
    fflush(stdout);

    /* First, end the session. */
    output_f = Gal_MakeFrame("Builtin.end_session", GAL_CLAUSE);
    GalSS_EnvWriteFrame(p->env, output_f, 0);
    Gal_FreeFrame(output_f);
      
    /* Next, shut down the connection. This ought
       to reset the poll. */      
    GalIO_SetCommDone(GalSS_EnvComm(p->env));
    /* DON'T DESTROY THE CONNECTION. In batch mode,
       we'll be inside a poll for that connection, and
       all sorts of bad things will happen. It's enough
       to set it to be done; that will force it to be
       destroyed when the current poll is finished. */
    break;
  }
  if (data)
    free(data);
}
コード例 #6
0
ファイル: external_api.c プロジェクト: junion/GalaxyWinPython
void GalHUB_SetHubLogTopDataDir(HUB *hub, char *dir, char *dir_key)
{
  hub->data_topdir_key = _gal_strdup(dir_key);
  Gal_SetProp(hub->globals, dir_key, Gal_StringObject(dir));
}
コード例 #7
0
ファイル: external_api.c プロジェクト: junion/GalaxyWinPython
void GalHUB_SetHubSessionId(HUB *hub, char *session_id, char *session_id_key)
{
  hub->session_id_key = _gal_strdup(session_id_key);
  Gal_SetProp(hub->globals, session_id_key, Gal_StringObject(session_id));
}