Ejemplo n.º 1
0
BOOL tts_playlist_add( TtsPlayList list, const char* text )
{
   int result = -1;
   const TtsProvider* provider = NULL;

   if ( !tts_enabled() )
      return FALSE;

   if ( !text )
   {
      roadmap_log( ROADMAP_ERROR, TTS_LOG_STR( "Cannot add NULL texts to the playlist" ) );
      return FALSE;
   }

   provider = _voice_service_provider( list->voice_id );
   switch ( provider->storage_type )
   {
      case __tts_db_data_storage__file:
      {
         TtsPath path;
         const char* parsed_text = _parse_text( text );
         if ( tts_cache_get( parsed_text, list->voice_id, NULL, &path ) )
         {
            result = roadmap_sound_list_add( list->sound_list, path.path );
            roadmap_log( ROADMAP_DEBUG, TTS_LOG_STR( "Adding text %s (Voice: %s). Path: %s to the playlist. Status: %d" ),
                  parsed_text, list->voice_id, path.path, result );

            if ( result == SND_LIST_ERR_NO_FILE )
            {
               const TtsDbEntry* db_entry = tts_db_entry( list->voice_id, parsed_text, NULL );
               TtsTextType text_type = tts_db_text_type( db_entry );

               roadmap_log( ROADMAP_WARNING, TTS_LOG_STR( "File %s doesn't exist!!!. Removing the entry!" ), path.path );
               tts_cache_remove( parsed_text, list->voice_id, __tts_db_data_storage__file );
               // Post new request if matches the current voice
               if ( !list->voice_id || !strcmp( list->voice_id, sgTtsVoiceId ) )
               {
                  tts_request_ex( parsed_text, text_type, NULL, NULL, TTS_FLAG_NONE );
                  tts_commit(); // Commit immediately in this case
               }
            }
         }
         break;
      }
      case __tts_db_data_storage__blob_record:
      {
         TtsData data;
         if ( tts_cache_get( _parse_text( text ), list->voice_id, &data, NULL ) )
            result = roadmap_sound_list_add_buf( list->sound_list, data.data, data.data_size );
         break;
      }
      default:
      {
         roadmap_log( ROADMAP_WARNING, "Data storage type %d is not supported" );
      }
   }

   return ( result >= 0 );
}
Ejemplo n.º 2
0
bool vrpn_Tracker_JsonNet::_parse(const char* buffer, int length) {
	Json::Value root;							// will contains the root value after parsing.
	// Beware collectcomment = true crashes
	bool parsingSuccessful = _pJsonReader->parse( buffer, root , false);
	if ( !parsingSuccessful ) {
		// report to the user the failure and their locations in the document.
		fprintf(stderr, "vrpn_Tracker_JsonNet parse error :%s\n",
						 _pJsonReader->getFormatedErrorMessages().c_str());
		fprintf(stderr, "%s\n",buffer);
		return false;
	}

	const Json::Value& constRoot = root;
	// Find MessageType
	const Json::Value& type = constRoot[MSG_KEY_TYPE]; 
	int messageType;
	if (!type.empty() && type.isConvertibleTo(Json::intValue)) {
		messageType = type.asInt();
		// HACK
	} else {
		fprintf(stderr, "vrpn_Tracker_JsonNet parse error : missing message type\n");
		return false;
	}
	switch (messageType) {
		// TODO cleanup
		case MSG_TYPE_TRACKER:
			return _parse_tracker_data(root);
			break;
		case MSG_TYPE_BUTTON:
			return _parse_button(root);
			break;
		case MSG_TYPE_ANALOG:
			return _parse_analog(root);
			break;
		case MSG_TYPE_TEXT:
			return _parse_text(root);
			break;
		default:
			;
	}
	return false;

	
}
Ejemplo n.º 3
0
void tts_request_ex( const char* text, TtsTextType text_type, TtsRequestCompletedCb completed_cb, void* user_context, int flags )
{
   const char *parsed_text;

   if ( !tts_enabled() )
   {
      roadmap_log(ROADMAP_WARNING, TTS_LOG_STR( "TTS is disabled cannot post synthesize request for %s." ), text );
      return;
   }

   if ( !text || !text[0] )
   {
      if ( completed_cb )
      {
         completed_cb( user_context, TTS_RES_STATUS_NULL_TEXT, "NULL" );
      }
      roadmap_log( ROADMAP_WARNING, TTS_LOG_STR( "NULL or empty text cannot be requested!" ) );
      return;
   }

   parsed_text = _parse_text( text );

   if ( tts_cache_exists( parsed_text, sgTtsVoiceId ) )
   {
      TtsRequest tts_request = TTS_REQUEST_INITIALIZER;
      tts_request.flags = flags;
      tts_request.text = parsed_text;
      _add_request_callback( &tts_request, completed_cb, user_context );

      _process_cached( &tts_request );
   }
   else
   {
      _queue_one( strdup( parsed_text ), text_type, completed_cb, user_context, flags );

      if ( sgActiveProvider->batch_request_limit == 1 )
      {
         // Commit immediately
         tts_commit();
      }
   }
}
Ejemplo n.º 4
0
BOOL tts_text_available( const char* text, const char* voice_id )
{
   BOOL result = tts_enabled() && tts_cache_exists( _parse_text( text ), voice_id );

   return result;
}