Пример #1
0
int main(int argc, char** argv)
{
  uint8_t *buf;
  size_t len;

  {
    struct stat buf;
    while (!stat(TEST_DBG, &buf)) {
      sleep(1);
    }
  }

  
  ECIHand handle = eciNew();
  if (!handle)
    return __LINE__;

  int fd = creat(PATHNAME_RAW_DATA, S_IRUSR|S_IWUSR);
  if (fd==-1)
    return __LINE__;

  eciRegisterCallback(handle, my_client_callback, (char*)NULL + fd);

  if (eciSetOutputBuffer(handle, MAX_SAMPLES, my_samples) == ECIFalse)
    return __LINE__;
  
  //  eciSetOutputFilename(handle, PATHNAME_RAW_DATA);

  if (eciAddText(handle, vh_quote) == ECIFalse)
    return __LINE__;

  if (eciSynthesize(handle) == ECIFalse)
    return __LINE__;

  if (eciSynchronize(handle) == ECIFalse)
    return __LINE__;

  if (eciDelete(handle) != NULL)
    return __LINE__;
  
 exit0:
  return 0;
}
Пример #2
0
bool ECISpeakTheText(const char* message)
{
    ttsTrace("ECI::SpeakTheText...");
    
    if (eciInstance == NULL_ECI_HAND) return false;
	    
        //prepare for UNICODE        
        /*switch (SelectedLanguage) {
        	case 8:
        	case 9:
				setlocale(LC_TYPE, "cht");
     			int len = strlen((char*)message)+1;
     			unsigned short *ut= (unsigned short*) malloc(len*sizeof(short));
			     if(ut) {
			         mbstowcs(ut, (char*)message, len);
			         eciAddText(eciInstance, ut);
			         free(ut);    
			     }

        	case 11:
        	case 13:
        	case 15:
        	break;
        	
        	case else:
        		eciAddText(eciInstance , message);
			break;
		}	*/
    	    
///     setlocale(LC_CTYPE, "C");        
    	eciAddText(eciInstance , message);
    	eciSynthesize(eciInstance);   	
    	//eciSynchronize(eciInstance);
    		
	return true;	
}
Пример #3
0
static int unserialize(struct msg_t *msg, size_t *msg_length)
{
  struct engine_t *engine = NULL;
  size_t effective_msg_length = 0;
  size_t allocated_msg_length = 0;

  ENTER();

  if (!msg || !msg_length) {
    err("LEAVE, args error(%d)",0);
    return EINVAL;
  }

  engine = (struct engine_t*)msg->engine;

  if ((*msg_length < MIN_MSG_SIZE)
      || (msg->id != MSG_TO_ECI_ID)
      || !msg_string(msg->func)
      || (*msg_length < MSG_HEADER_LENGTH + msg->effective_data_length)
      || (engine && !check_engine(engine))) {
    msg("recv erroneous msg");
    memset(msg, 0, MIN_MSG_SIZE);
    msg->id = MSG_TO_APP_ID;
    msg->func = MSG_UNDEFINED;
    *msg_length = MIN_MSG_SIZE;
    msg->res = ECIFalse;
    dbg("send msg '%s', length=%d, res=0x%x (#%d)", msg_string(msg->func), msg->effective_data_length, msg->res, msg->count);
    LEAVE();
    return 0;
  }

  dbg("recv msg '%s', length=%d, engine=%p (#%d)", msg_string(msg->func), msg->effective_data_length, engine, msg->count);

  msg->id = MSG_TO_APP_ID;
  msg->effective_data_length = 0;

  switch(msg->func) {
  case MSG_ADD_TEXT:
    if (msg->data[msg->effective_data_length-1] != 0) {
      err("LEAVE, %s, data error, length=%d, <0x%x 0x%x 0x%x>", msg_string(msg->func), msg->effective_data_length, msg->data[msg->effective_data_length-3], msg->data[msg->effective_data_length-2], msg->data[msg->effective_data_length-1]);
      msg->res = ECIFalse;
    } else {
      dbg("text=%s", (char*)msg->data);
      dbg("eciAddText: handle=%p, data=%s", engine->handle, msg->data);
      msg->res = (uint32_t)eciAddText(engine->handle, msg->data);
    }
    break;

  case MSG_CLEAR_ERRORS:
    dbg("eciClearErrors: handle=%p", engine->handle);
    eciClearErrors(engine->handle);
    break;

  case MSG_CLEAR_INPUT:
    dbg("eciClearInput: handle=%p", engine->handle);
    eciClearInput(engine->handle);
    break;

  case MSG_COPY_VOICE:
    dbg("eciCopyVoice: handle=%p, from %d to %d", engine->handle, msg->args.cv.iVoiceFrom, msg->args.cv.iVoiceTo);
    msg->res = (uint32_t)eciCopyVoice(engine->handle, msg->args.cv.iVoiceFrom, msg->args.cv.iVoiceTo);
    break;

  case MSG_DELETE_DICT:
    dbg("eciDeleteDict: handle=%p, dict=%p", engine->handle, (char*)NULL + msg->args.dd.hDict);
    msg->res = (uint32_t)eciDeleteDict(engine->handle, (char*)NULL + msg->args.dd.hDict);
    break;

  case MSG_ERROR_MESSAGE:
    BUILD_ASSERT(MSG_HEADER_LENGTH + MAX_ERROR_MESSAGE <= PIPE_MAX_BLOCK);
    dbg("eciErrorMessage: handle=%p", engine->handle);
    eciErrorMessage(engine->handle, msg->data);
    msg->effective_data_length = MAX_ERROR_MESSAGE;
    msg("error=%s", (char*)msg->data);
    break;

  case MSG_GET_AVAILABLE_LANGUAGES: {
    struct msg_get_available_languages_t *lang = (struct msg_get_available_languages_t *)msg->data;
    BUILD_ASSERT(MSG_HEADER_LENGTH + sizeof(struct msg_get_available_languages_t) <= PIPE_MAX_BLOCK);
    lang->nb = sizeof(lang->languages)/sizeof(lang->languages[0]);
    dbg("eciGetAvailableLanguages");
    msg->res = eciGetAvailableLanguages(lang->languages, &lang->nb);
    msg->effective_data_length = sizeof(struct msg_get_available_languages_t);
    dbg("nb lang=%d, msg->res=%d", lang->nb, msg->res);
  }
    break;

  case MSG_GET_DEFAULT_PARAM:
    dbg("eciGetDefaultParam: handle=%p", engine->handle);
    msg->res = (uint32_t)eciGetDefaultParam(msg->args.gp.Param);
    break;

  case MSG_GET_DICT:
    dbg("eciGetDict: handle=%p", engine->handle);
    msg->res = (uint32_t)eciGetDict(engine->handle);
    break;

  case MSG_GET_PARAM:
    dbg("eciGetParam: handle=%p, param=%d", engine->handle, msg->args.gp.Param);
    msg->res = (uint32_t)eciGetParam(engine->handle, msg->args.gp.Param);
    break;

  case MSG_GET_VOICE_PARAM:
    dbg("eciGetVoiceParam: handle=%p, voice=%d, param=%d", engine->handle,
	msg->args.gvp.iVoice, msg->args.gp.Param);
    msg->res = (uint32_t)eciGetVoiceParam(engine->handle, msg->args.gvp.iVoice,
					  msg->args.gvp.Param);
    break;

  case MSG_INSERT_INDEX:
    dbg("eciInsertIndex: handle=%p", engine->handle);
    msg->res = (uint32_t)eciInsertIndex(engine->handle, msg->args.ii.iIndex);
    break;

  case MSG_LOAD_DICT:
    dbg("eciLoadDict: handle=%p, hDict=%p, DictVol=0x%x, filename=%s",
	engine->handle,
	(char*)NULL + msg->args.ld.hDict,
	msg->args.ld.DictVol, msg->data);
    msg->res = eciLoadDict(engine->handle, (char*)NULL + msg->args.ld.hDict, msg->args.ld.DictVol, msg->data);
    break;

  case MSG_NEW: {    
    dbg("eciNew");
    ECIHand h = eciNew();
    if (h) {
      engine = calloc(1, sizeof(struct engine_t));
      if (engine) {
	engine->id = ENGINE_ID;
	engine->handle = h;
	dbg("MSG_NEW: engine=%p, handle=%p", engine, h);
      }
    }
    msg->res = (uint32_t)engine;
  }
    break;

  case MSG_NEW_DICT:
    dbg("eciNewDict: handle=%p", engine->handle);
    msg->res = (uint32_t)eciNewDict(engine->handle);
    break;

  case MSG_NEW_EX: {
    dbg("eciNewEx: value=%d", msg->args.ne.Value);
    ECIHand h = eciNewEx(msg->args.ne.Value);
    if (h) {
      engine = calloc(1, sizeof(struct engine_t));
      if (engine) {
	engine->id = ENGINE_ID;
	engine->handle = h;
      }
    }
    msg->res = (uint32_t)engine;
  }
    break;

  case MSG_PAUSE:
    dbg("eciPause: handle=%p", engine->handle);
    msg->res = (uint32_t)eciPause(engine->handle, msg->args.p.On);
    break;

  case MSG_PROG_STATUS:
    dbg("eciProgStatus: handle=%p", engine->handle);
    msg->res = eciProgStatus(engine->handle);
    break;

  case MSG_REGISTER_CALLBACK: {
    ECICallback cb = NULL;
    if (msg->args.rc.Callback)
      cb = my_callback;
    dbg("eciRegisterCallback, engine=%p, handle=%p, cb=%p", engine, engine->handle, cb);
    eciRegisterCallback(engine->handle, cb, engine);
  }
    break;

  case MSG_RESET:
    dbg("eciReset: handle=%p", engine->handle);
    eciReset(engine->handle);
    break;

  case MSG_SET_DEFAULT_PARAM:
    dbg("eciSetDefaultParam: handle=%p, p=%d, v=%d", engine->handle, msg->args.sp.Param, msg->args.sp.iValue);
    msg->res = (uint32_t)eciSetDefaultParam(msg->args.sp.Param, msg->args.sp.iValue);
    break;

  case MSG_SET_DICT:
    dbg("eciSetDict: handle=%p, d=%p", engine->handle, (char*)NULL + msg->args.sd.hDict);
    msg->res = (uint32_t)eciSetDict(engine->handle, (char*)NULL + msg->args.sd.hDict);
    break;

  case MSG_SET_OUTPUT_DEVICE:
    dbg("eciSetOutputDevice: handle=%p, dev=%d", engine->handle, msg->args.sod.iDevNum);
    msg->res = (uint32_t)eciSetOutputDevice(engine->handle, msg->args.sod.iDevNum);
    break;

  case MSG_SET_PARAM:
    dbg("eciSetParam: handle=%p, p=%d, v=%d", engine->handle, msg->args.sp.Param, msg->args.sp.iValue);
    msg->res = (uint32_t)eciSetParam(engine->handle, msg->args.sp.Param, msg->args.sp.iValue);
    break;

  case MSG_SET_VOICE_PARAM:
    dbg("eciSetVoiceParam: handle=%p, p=%d, v=%d", engine->handle, msg->args.svp.iVoice, msg->args.svp.iValue);
    msg->res = (uint32_t)eciSetVoiceParam(engine->handle, msg->args.svp.iVoice, msg->args.svp.Param, msg->args.svp.iValue);
    break;

  case MSG_SET_OUTPUT_BUFFER:
    set_output_buffer(my_voxind, engine, msg);
    break;

  case MSG_SET_OUTPUT_FILENAME:
    dbg("eciSetOutputFilename: handle=%p, d=%s", engine->handle, msg->data);
    msg->res = (uint32_t)eciSetOutputFilename(engine->handle, msg->data);
    break;

  case MSG_SYNTHESIZE:
    dbg("eciSynthesize: handle=%p", engine->handle);
    msg->res = (uint32_t)eciSynthesize(engine->handle);
    break;

  case MSG_SYNCHRONIZE:
    dbg("eciSynchronize: handle=%p", engine->handle);
    msg->res = (uint32_t)eciSynchronize(engine->handle);
    break;

  case MSG_SPEAKING:
    dbg("eciSpeaking: handle=%p", engine->handle);
    msg->res = (uint32_t)eciSpeaking(engine->handle);
    break;

  case MSG_STOP:
    dbg("eciStop: handle=%p", engine->handle);
    msg->res = (uint32_t)eciStop(engine->handle);
    break;

  case MSG_VERSION:
    BUILD_ASSERT(MSG_HEADER_LENGTH + MAX_VERSION <= PIPE_MAX_BLOCK);
    dbg("eciVersion");
    eciVersion(msg->data);
    msg->effective_data_length = MAX_VERSION;
    dbg("version=%s", msg->data);
    break;

  default:
    msg->res = ECIFalse;
    break;
  }

  *msg_length = MSG_HEADER_LENGTH + msg->effective_data_length;

 exit0:
  dbg("send msg '%s', length=%d, res=0x%x (#%d)", msg_string(msg->func), msg->effective_data_length, msg->res, msg->count);
  LEAVE();
  return 0;
}
Пример #4
0
int main(int argc, char **argv)
{
  uint8_t *buf;
  size_t len;
  char version[20];
  
  {
    struct stat buf;
    while (!stat(TEST_DBG, &buf)) {
      sleep(1);
    }
  }

  eciVersion(version);
    
  ECIHand handle = eciNew();
  if (!handle)
    return __LINE__;

  int fd = creat(PATHNAME_RAW_DATA, S_IRUSR|S_IWUSR);
  if (fd==-1)
    return __LINE__;

  eciRegisterCallback(handle, my_client_callback, (char*)NULL + fd);
  if (eciSetOutputBuffer(handle, MAX_SAMPLES, my_samples) == ECIFalse)
    return __LINE__;
  
  //  eciSetOutputFilename(handle, PATHNAME_RAW_DATA);

  if (eciAddText(handle, vh_quote) == ECIFalse)
    return __LINE__;
  
  if (eciSynthesize(handle) == ECIFalse)
    return __LINE__;

  #define ONE_MILLISECOND_IN_NANOSECOND 1000000 
  struct timespec req;
  req.tv_sec=0;
  req.tv_nsec=ONE_MILLISECOND_IN_NANOSECOND;
  
  while(eciSpeaking(handle) == ECIFalse)
    nanosleep(&req, NULL);

  int i=0;
  while((eciSpeaking(handle) == ECITrue) && (i<50)) {    
    nanosleep(&req, NULL);
    i++;
  }

  if (eciStop(handle) == ECIFalse) {
    char error[256];
    eciErrorMessage(handle, error);
    fprintf(stderr, "eciStop error=%s, status=0x%x\n", error, eciProgStatus(handle));
    eciClearErrors(handle);
    eciErrorMessage(handle, error);
  }

  while(eciSpeaking(handle) == ECITrue) {    
    nanosleep(&req, NULL);
  }
  
  if (eciDelete(handle) != NULL)
    return __LINE__;
    
 exit0:
  return 0;
}