コード例 #1
0
int main(void) {
	float noiseLevel = recordSample();
	printf("%f", noiseLevel);
	return EXIT_SUCCESS;
}
コード例 #2
0
void editModelItem(ModelItem *model_item)
{
  int width = 65, height = 22, i, j;             /***** ncurses related variables */
  WINDOW *itemscr = popupWindow (width, height);

  int top = 0, current = 0;   /***** menu selection related variables */
  int max_view = 6;

  int input_field_width = 40; /***** width of string input field */

  int request_finish = 0;     /***** request_finish = 1 breaks the main while loop */

  while (!request_finish)
  {
    wattrset (itemscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL);  /***** set bg color of the dialog */

    /*****
     * draw a box around the dialog window
     * and empty it.
     *****/
    werase (itemscr);
    box (itemscr, 0, 0);
    for (i = 1; i < width-1; i++)
      for (j = 1; j < height-1; j++)
	mvwaddch(itemscr, j, i, ' ');

    /***** dialog header */

    mvwaddstr(itemscr, 1, 2, "Edit Speaker Model Item");
    mvwaddseparator(itemscr, 2, width);

    /***** display help at the bottom */

    mvwaddseparator(itemscr, height-4, width);
    mvwaddstr(itemscr, height-3, 2, "r = record sample, d = delete sample, enter = play sample");
    mvwaddstr(itemscr, height-2, 2, "b = back to model menu, l = edit label, c = edit command");

    /***** display information about current speaker item */

    mvwaddstr(itemscr, 4, 2, "Label   :");
    mvwaddnstr(itemscr, 4, 12, model_item->label, input_field_width);
    mvwaddstr(itemscr, 5, 2, "Command :");
    mvwaddnstr(itemscr, 5, 12, model_item->command, input_field_width);

    mvwaddstr(itemscr, 7, 2, "Number of samples:");
    mvwaddint(itemscr, 7, 21, model_item->number_of_samples);

    /***** show sample utterances in a list. */

    mvwaddstr(itemscr, 9, 4, "ID"); /***** header */
    for (i = 0; i < 28; i++)
      mvwaddch(itemscr,10, 3+i, ACS_HLINE);

    /***** list items */

    for (i = 0; i < MIN2(model_item->number_of_samples, max_view); i++)
    {
      setHighlight(itemscr, active, i == current);
      mvwaddstr(itemscr,11+i,  3, "                            ");
      mvwaddstr(itemscr,11+i,  4, getModelItemSample(model_item, top+i)->id);
    }
    wattroff(itemscr, A_REVERSE);

    /***** up/down arrows indicate that not all items can be displayed */

    if (top > 0)
    {
      mvwaddch(itemscr,11, 2, ACS_UARROW);
      mvwaddch(itemscr,11+1, 2, ACS_VLINE);
    }
    if (model_item->number_of_samples > max_view && top+max_view <= model_item->number_of_samples-1)
    {
      mvwaddch(itemscr,11+max_view-2, 2, ACS_VLINE);
      mvwaddch(itemscr,11+max_view-1, 2, ACS_DARROW);
    }

    wmove(itemscr, 1,26); /***** move cursor to a convenient location */
    wrefresh(itemscr);    /***** refresh dialog window */

    /* process the command keystroke */

    switch(getch())
    {
    case KEY_UP: /***** cursor up */
      if (top+current > 0)
      {
	if (current > 0)
	 current--;
	else
	  top--;
      }
      break;
    case KEY_DOWN: /***** cursor down */
      if (top+current < model_item->number_of_samples-1)
      {
	if (current < max_view-1)
	 current++;
	else
	  top++;
      }
      break;
    case 'b':      /***** leave menu */
      request_finish = 1;
      break;
    case ENTER:    /***** play selected utterance */
      if (model_item->number_of_samples > 0)
      {
	int width = 42, height = 8, i, j;                  /* ncurses related variables */
	WINDOW *playbackscr = popupWindow (width, height);

	wattrset (playbackscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */
	/*****
	 * draw a box around the dialog window
	 * and empty it.
	 *****/
	werase (playbackscr);
	box (playbackscr, 0, 0);
	for (i = 1; i < width-1; i++)
	  for (j = 1; j < height-1; j++)
	    mvwaddch(playbackscr, j, i, ' ');

	/***** dialog header */
	
	mvwaddstr(playbackscr, 1, 2, "Playback");
	mvwaddseparator(playbackscr, 2, width);

	/***** play wave if present */
	
	if (getModelItemSample(model_item, top+current)->has_wav)
	{
	  /***** dialog message */
	
	  mvwaddstr(playbackscr, 3, 2,"Utterance is being played ...      ");
	  /* mvwaddstrcntr(playbackscr, 6, width, "Press any key to cancel ..."); */
	
	  wmove(playbackscr, 1, 11); /***** move cursor to an appropriate location */
	  wrefresh (playbackscr);    /***** refresh dialog window */

	  /***** if play fails or was cancelled ....*/
	
	  if (playSample(getModelItemSample(model_item, top+current)) != AUDIO_OK)
	  {
	    /***** display information */
	
	    mvwaddstr(playbackscr, 1, 2, "Warning!    ");
	    mvwaddstr(playbackscr, 3, 2,"Either playback has been cancelled  ");
	    mvwaddstr(playbackscr, 4, 2,"or wave couldn't be sent to your    ");
	    mvwaddstr(playbackscr, 5, 2,"soundcard !                         ");
	    mvwaddstrcntr(playbackscr, 6, width, "Press any key to continue ...");

	    wmove(playbackscr, 1, 11); /***** move cursor to an appropriate location */
	    wrefresh (playbackscr);    /***** refresh dialog window */
	    getch();                   /***** wait for keyboard input */
	  }
	}
	else /***** no wave data present! */
	{
	  mvwaddstr(playbackscr, 3, 2,"Utterance can't be played! No wave  ");
	  mvwaddstr(playbackscr, 4, 2,"data available! Note: KvoiceControl ");
	  mvwaddstr(playbackscr, 5, 2,"did NOT save the original wave data!");
	  mvwaddstrcntr(playbackscr, 6, width, "Press any key to cancel ...");
	
	  wmove(playbackscr, 1, 11); /***** move cursor to an appropriate location */
	  wrefresh (playbackscr);    /***** refresh dialog window */
	  getch();                   /***** wait for keyboard input */
	}
	
	delwin(playbackscr);   /***** delete ncurses dialog window */
      }
      break;
    case 'r':   /***** record sample utterance */
      {
	int width = 42, height = 8, i, j;   /***** ncurses related variables */
	WINDOW *recordscr = popupWindow (width, height);

	ModelItemSample *new_sample; /***** temporary pointer to new utterance */
	
	wattrset (recordscr, color_term ? COLOR_PAIR(2) | A_BOLD : A_NORMAL); /***** set bg color of the dialog */

	/*****
	 * draw a box around the dialog window
	 * and empty it.
	 *****/
	werase (recordscr);
	box (recordscr, 0, 0);
	for (i = 1; i < width-1; i++)
	  for (j = 1; j < height-1; j++)
	    mvwaddch(recordscr, j, i, ' ');

	/***** dialog header */
	
	mvwaddstr(recordscr, 1, 2, "Recording");
	mvwaddseparator(recordscr, 2, width);

	/***** dialog message */
	
	mvwaddstr(recordscr, 3, 2,"Utterance is recorded automatically!");
	mvwaddstr(recordscr, 4, 2,"Please say what you want to say ...");
	mvwaddstrcntr(recordscr, 6, width, "Press any key to cancel ...");
	
	wmove(recordscr, 1, 12); /***** move cursor to a convenient location */
	wrefresh (recordscr);    /***** refresh dialog screen */
	
	new_sample = recordSample(); /***** auto record a sample utterance */
	
	if (new_sample != NULL) /***** if the recording was successful ... */
	{
	  appendModelItemSample(model_item, new_sample); /***** add the sample to the model */

	  /***** set cursor to be over new sample utterance */
	
	  current = model_item->number_of_samples-1 - top;
	  while (current > max_view-1)
	  {
	    current--;
	    top++;
	  }
	}
	else /***** recording has failed or was cancelled */
	{
	  /***** dialog message */
	
	  mvwaddstr(recordscr, 1, 2, "Cancel!    ");
	  mvwaddstr(recordscr, 3, 2,"Nothing has been recorded! Either   ");
	  mvwaddstr(recordscr, 4, 2,"you cancelled or no data could be   ");
	  mvwaddstr(recordscr, 5, 2,"recorded !                          ");
	  mvwaddstrcntr(recordscr, 6, width, "Press any key to continue ...");

	  wmove(recordscr, 1, 10); /***** move cursor to a convenient location */
	  wrefresh (recordscr);    /***** refresh dialog screen   */
	  getch();                 /***** wait for keyboard input */
	}
	
	delwin(recordscr);   /***** delete ncurses dialog window */
      }
      break;
    case 'l': /***** edit label */
      {
	/*****
	 * use wstringInput to edit the label of the current utterance
	 * if the label has changed, switch 'modified' to 1
	 *****/
	char tmp_string[1000];
	strcpy(tmp_string, model_item->label);
	free(model_item->label);
	model_item->label = wstringInput(itemscr, 4, 12, 255, input_field_width, tmp_string);
	if (strcmp(tmp_string, model_item->label) != 0)
	  modified = 1;
      }
      break;
    case 'c': /***** edit command */
      {
	/*****
	 * use wstringInput to edit the commandd of the current utterance
	 * if the command has changed, switch 'modified' to 1
	 *****/
	char tmp_string[1000];
	strcpy(tmp_string, model_item->command);
	free(model_item->command);
	model_item->command = wstringInput(itemscr, 5, 12, 255, input_field_width, tmp_string);
	if (strcmp(tmp_string, model_item->command) != 0)
	  modified = 1;
      }
      break;
    case 'd':
      /*****
       * delete currently selected sample utterance from model item
       * and switch 'modified' to 1
       *****/
      deleteModelItemSample(model_item, top+current);
      modified = 1;

      /***** set cursor to a valid value */
	
      if (top+current == model_item->number_of_samples)
      {
	if (top > 0)
	  top--;
	else if (current > 0)
	  current--;
      }
      break;
    }
  }
}