Aisound::Aisound() { ivTTSErrID ivReturn; usleep(60000); /* ·ÖÅä¶Ñ */ pHeap = (ivPByte)malloc(ivTTS_HEAP_SIZE); memset(pHeap, 0, ivTTS_HEAP_SIZE); /* ³õʼ»¯×ÊÔ´ */ /* ¿ÉÒÔÓжà¸ö×ÊÔ´°ü£¬¿ÉÒÔ·Ö°ü*/ tResPackDesc.pCBParam = fopen(RESOURCE_FILE, "rb"); if( NULL == tResPackDesc.pCBParam ) { throw; } tResPackDesc.pfnRead = ReadResCB; tResPackDesc.pfnMap = NULL; tResPackDesc.nSize = 0; /* TTSÄÚ²¿Ê¹Óà */ tResPackDesc.pCacheBlockIndex = NULL; tResPackDesc.pCacheBuffer = NULL; tResPackDesc.nCacheBlockSize = 0; tResPackDesc.nCacheBlockCount = 0; tResPackDesc.nCacheBlockExt = 0; /* ´´½¨ TTS ʵÀý */ // ivReturn = ivTTS_Create(&hTTS, (ivPointer)pHeap, ivTTS_HEAP_SIZE, ivNull, (ivPResPackDescExt)&tResPackDesc, (ivSize)1,&tUserInfo); ivReturn = ivTTS_Create(&hTTS, (ivPointer)pHeap, ivTTS_HEAP_SIZE, ivNull, (ivPResPackDescExt)&tResPackDesc, (ivSize)1, NULL); /* ÉèÖÃÒôƵÊä³ö»Øµ÷ */ ivReturn = ivTTS_SetParam(hTTS, ivTTS_PARAM_OUTPUT_CALLBACK, (ivUInt32)OutputCB); /* ÉèÖÃÊäÈëÎı¾´úÂëÒ³ */ ivReturn = ivTTS_SetParam(hTTS, ivTTS_PARAM_INPUT_CODEPAGE, ivTTS_CODEPAGE_GBK); /* ÉèÖÃÓïÖÖ */ ivReturn = ivTTS_SetParam(hTTS, ivTTS_PARAM_LANGUAGE, ivTTS_LANGUAGE_AUTO); /* ÉèÖÃÒôÁ¿ */ ivReturn = ivTTS_SetParam(hTTS, ivTTS_PARAM_VOLUME, ivTTS_VOLUME_NORMAL); /*ÉèÖÃÓïËÙ*/ ivReturn = ivTTS_SetParam(hTTS, ivTTS_PARAM_VOICE_SPEED, ivTTS_VOLUME_NORMAL); /************************************************************************ ¿éʽºÏ³É ************************************************************************/ /* ÉèÖ÷¢ÒôÈËΪ XIAOYAN */ ivReturn = ivTTS_SetParam(hTTS, ivTTS_PARAM_ROLE, ivTTS_ROLE_XIAOYAN); }
bool AISound::create(const QLocale & locale) { if (initialized_) { qDebug("Already initialized."); return true; } #ifdef BUILD_FOR_ARM // Check resource. QDir dir(QDir::home()); QString path = SHARE_ROOT; if (!path.isEmpty()) { dir.cd(path); } if (!dir.cd("tts")) { qDebug("Could not change to tts folder"); return false; } file_.setFileName(dir.absoluteFilePath("resource.irf")); if (!file_.open(QIODevice::ReadOnly)) { qWarning("Can not load resource.irf file."); return false; } qDebug("load resource file done."); // Allocate memory. if (heap_ == 0) { heap_ = new unsigned char[HEAP_SIZE]; memset(heap_, 0, HEAP_SIZE); } ivTTSErrID ivReturn = ivTTS_ERR_OK; resource_desc_.pCBParam = this; resource_desc_.pfnRead = readResouceCallback; resource_desc_.pfnMap = NULL; resource_desc_.nSize = 0; resource_desc_.pCacheBlockIndex = (ivPUInt8)malloc(ivTTS_CACHE_COUNT + ivTTS_CACHE_EXT); resource_desc_.pCacheBuffer = (ivPUInt8)malloc((ivTTS_CACHE_COUNT + ivTTS_CACHE_EXT)*(ivTTS_CACHE_SIZE)); resource_desc_.nCacheBlockSize = ivTTS_CACHE_SIZE; resource_desc_.nCacheBlockCount = ivTTS_CACHE_COUNT; resource_desc_.nCacheBlockExt = ivTTS_CACHE_EXT; // create tts engine instance. ivReturn = ivTTS_Create(&handle_, (ivPointer)heap_, HEAP_SIZE, this, &resource_desc_, 1); // callback function for output. ivReturn = ivTTS_SetParam(handle_, ivTTS_PARAM_OUTPUT_CALLBACK, (ivUInt32)outputCallback); // code page ivReturn = ivTTS_SetParam(handle_, ivTTS_PARAM_INPUT_CODEPAGE, ivTTS_CODEPAGE_UTF8); // Language ivReturn = ivTTS_SetParam(handle_, ivTTS_PARAM_LANGUAGE, ivTTS_LANGUAGE_CHINESE); // Volume ivReturn = ivTTS_SetParam(handle_, ivTTS_PARAM_VOLUME, ivTTS_VOLUME_MAX); // speaker ivReturn = ivTTS_SetParam(handle_, ivTTS_PARAM_ROLE, ivTTS_ROLE_ANITA); // speed ivReturn = ivTTS_SetParam(handle_, ivTTS_PARAM_VOICE_SPEED, ivTTS_SPEED_NORMAL); // pitch ivReturn = ivTTS_SetParam(handle_, ivTTS_PARAM_VOICE_PITCH, ivTTS_PITCH_NORMAL); // Style ivReturn = ivTTS_SetParam(handle_, ivTTS_PARAM_SPEAK_STYLE, ivTTS_STYLE_PLAIN); #endif initialized_ = true; return true; }