Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4033 lines
112 KiB

  1. /*******************************************************************************
  2. * Frontend.cpp *
  3. *--------------*
  4. * Description:
  5. * This module is the main implementation file for the CFrontend class.
  6. *-------------------------------------------------------------------------------
  7. * Created By: mc Date: 03/12/99
  8. * Copyright (C) 1999 Microsoft Corporation
  9. * All Rights Reserved
  10. *
  11. *******************************************************************************/
  12. //--- Additional includes
  13. #include "stdafx.h"
  14. #include "ms_entropicengine.h"
  15. #include "Frontend.h"
  16. #include "spdebug.h"
  17. #include "FeedChain.h"
  18. #include "AlloOps.h"
  19. #include "sapi.h"
  20. #include "StdSentEnum.h"
  21. static bool IsVowel ( char* ph );
  22. //-----------------------------
  23. // Data.cpp
  24. //-----------------------------
  25. extern const short g_IPAToAllo[];
  26. extern const float g_RateScale[];
  27. inline short GetPhoneF0( float *pF0Contour, float CurrentTime, float Length )
  28. {
  29. float Total = 0;
  30. int startIndex = (int) ( CurrentTime / PITCH_BUF_RES + 0.5 );
  31. int endIndex = (int) ( ( CurrentTime + Length ) / PITCH_BUF_RES + 0.5 );
  32. for ( int i = startIndex; i < endIndex; i++ )
  33. {
  34. Total += pF0Contour[i];
  35. }
  36. Total /= endIndex - startIndex;
  37. return (short) Total;
  38. }
  39. const char* OldMapPhoneSet (ALLO_CODE code)
  40. {
  41. static struct tagPhoneMap {
  42. const char* name;
  43. ALLO_CODE code;
  44. } phoneMap [] = {
  45. {"iy", _IY_},
  46. {"ih", _IH_},
  47. {"eh", _EH_},
  48. {"ae", _AE_},
  49. {"aa", _AA_},
  50. {"ah", _AH_},
  51. {"ao", _AO_},
  52. {"uh", _UH_},
  53. {"ax", _AX_},
  54. {"axr", _ER_}, // or "er"
  55. {"ey", _EY_},
  56. {"ay", _AY_},
  57. {"oy", _OY_},
  58. {"aw", _AW_},
  59. {"ow", _OW_},
  60. {"uw", _UW_},
  61. {"ix", _IX_},
  62. {"sil", _SIL_},
  63. {"w", _w_},
  64. {"y", _y_},
  65. {"r", _r_},
  66. {"l", _l_},
  67. {"hh", _h_},
  68. {"m", _m_},
  69. {"n", _n_},
  70. {"ng", _NG_},
  71. {"f", _f_},
  72. {"v", _v_},
  73. {"th", _TH_},
  74. {"dh", _DH_},
  75. {"s", _s_},
  76. {"z", _z_},
  77. {"sh", _SH_},
  78. {"zh", _ZH_},
  79. {"p", _p_},
  80. {"b", _b_},
  81. {"t", _t_},
  82. {"d", _d_},
  83. {"k", _k_},
  84. {"g", _g_},
  85. {"ch", _CH_},
  86. {"jh", _JH_},
  87. {"dx", _DX_},
  88. {"", _STRESS1_},
  89. {"", _STRESS2_},
  90. {"", _EMPHSTRESS_},
  91. {"", _SYLLABLE_}
  92. };
  93. static int nPhonesMap = sizeof (phoneMap) / sizeof(phoneMap[0]);
  94. int i;
  95. for ( i = 0; i < nPhonesMap; i++ )
  96. {
  97. if (code == phoneMap[i].code)
  98. {
  99. return phoneMap[i].name;
  100. }
  101. }
  102. return "";
  103. }
  104. const char* NewMapPhoneSet (ALLO_CODE code)
  105. {
  106. static struct tagPhoneMap {
  107. const char* name;
  108. ALLO_CODE code;
  109. } phoneMap [] = {
  110. {"iy", _IY_},
  111. {"ih", _IH_},
  112. {"eh", _EH_},
  113. {"ae", _AE_},
  114. {"aa", _AA_},
  115. {"ah", _AH_},
  116. {"ao", _AO_},
  117. {"uh", _UH_},
  118. {"ax", _AX_},
  119. {"er", _ER_}, // or "er"
  120. {"ey", _EY_},
  121. {"ay", _AY_},
  122. {"oy", _OY_},
  123. {"aw", _AW_},
  124. {"ow", _OW_},
  125. {"uw", _UW_},
  126. {"ix", _IX_},
  127. {"sil", _SIL_},
  128. {"w", _w_},
  129. {"y", _y_},
  130. {"r", _r_},
  131. {"l", _l_},
  132. {"h", _h_},
  133. {"m", _m_},
  134. {"n", _n_},
  135. {"ng", _NG_},
  136. {"f", _f_},
  137. {"v", _v_},
  138. {"th", _TH_},
  139. {"dh", _DH_},
  140. {"s", _s_},
  141. {"z", _z_},
  142. {"sh", _SH_},
  143. {"zh", _ZH_},
  144. {"p", _p_},
  145. {"b", _b_},
  146. {"t", _t_},
  147. {"d", _d_},
  148. {"k", _k_},
  149. {"g", _g_},
  150. {"ch", _CH_},
  151. {"jh", _JH_},
  152. {"dx", _DX_},
  153. {"", _STRESS1_},
  154. {"", _STRESS2_},
  155. {"", _EMPHSTRESS_},
  156. {"", _SYLLABLE_}
  157. };
  158. static int nPhonesMap = sizeof (phoneMap) / sizeof(phoneMap[0]);
  159. int i;
  160. for ( i = 0; i < nPhonesMap; i++ )
  161. {
  162. if (code == phoneMap[i].code)
  163. {
  164. return phoneMap[i].name;
  165. }
  166. }
  167. return "";
  168. }
  169. /*****************************************************************************
  170. * CFrontend::CFrontend *
  171. *----------------------*
  172. * Description:
  173. *
  174. ********************************************************************** MC ***/
  175. CFrontend::CFrontend()
  176. {
  177. SPDBG_FUNC( "CFrontend::CFrontend" );
  178. #ifdef USE_VOICEDATAOBJ
  179. m_pUnits = NULL;
  180. #endif
  181. m_unitCount = 0;
  182. m_CurUnitIndex = 0;
  183. m_pAllos = NULL;
  184. m_pSrcObj = NULL;
  185. m_fNewPhoneSet = FALSE;
  186. } /* CFrontend::CFrontend */
  187. /*****************************************************************************
  188. * CFrontend::~CFrontend *
  189. *-----------------------*
  190. * Description:
  191. *
  192. ********************************************************************** MC ***/
  193. CFrontend::~CFrontend()
  194. {
  195. SPDBG_FUNC( "CFrontend::~CFrontend" );
  196. #ifdef USE_VOICEDATAOBJ
  197. DisposeUnits();
  198. #endif
  199. if( m_pAllos )
  200. {
  201. delete m_pAllos;
  202. m_pAllos = NULL;
  203. }
  204. DeleteTokenList();
  205. } /* CFrontend::~CFrontend */
  206. /*****************************************************************************
  207. * CFrontend::CntrlToRatio *
  208. *-------------------------*
  209. * Description:
  210. * Return rate ratio from control
  211. *
  212. ********************************************************************** MC ***/
  213. float CFrontend::CntrlToRatio( long rateControl )
  214. {
  215. SPDBG_FUNC( "CFrontend::CntrlToRatio" );
  216. float rateRatio;
  217. if( rateControl < 0 )
  218. {
  219. //--------------------------------
  220. // DECREASE the rate
  221. //--------------------------------
  222. if( rateControl < MIN_USER_RATE )
  223. {
  224. rateControl = MIN_USER_RATE; // clip to min
  225. }
  226. rateRatio = 1.0f / ::g_RateScale[0 - rateControl];
  227. }
  228. else
  229. {
  230. //--------------------------------
  231. // INCREASE the rate
  232. //--------------------------------
  233. if( rateControl > MAX_USER_RATE )
  234. {
  235. rateControl = MAX_USER_RATE; // clip to max
  236. }
  237. rateRatio = ::g_RateScale[rateControl];
  238. }
  239. return rateRatio;
  240. } /* CFrontend::CntrlToRatio */
  241. /*****************************************************************************
  242. * CFrontend::Init *
  243. *-----------------*
  244. * Description:
  245. * Init voice dependent variables, call once when object is created+++
  246. *
  247. ********************************************************************** MC ***/
  248. #ifdef USE_VOICEDATAOBJ
  249. HRESULT CFontend::Init( CVoiceData* pVoiceDataObj, CFeedChain *pSrcObj, MSVOICEINFO* pVoiceInfo,
  250. EntropicPitchInfo PitchInfo, bool fNewPhoneSet )
  251. #else
  252. HRESULT CFrontend::Init( void* pVoiceDataObj, CFeedChain *pSrcObj, void* pVoiceInfo,
  253. EntropicPitchInfo PitchInfo, bool fNewPhoneSet )
  254. #endif
  255. {
  256. SPDBG_FUNC( "CFrontend::Init" );
  257. HRESULT hr = S_OK;
  258. m_pSrcObj = pSrcObj;
  259. m_BasePitch = PitchInfo.BasePitch;
  260. #ifdef USE_VOICEDATAOBJ
  261. m_pVoiceDataObj = pVoiceDataObj;
  262. m_ProsodyGain = ((float)pVoiceInfo->ProsodyGain) / 100.0f;
  263. m_SampleRate = (float)pVoiceInfo->SampleRate;
  264. #endif
  265. // NOTE: move these to voice data?
  266. // m_VoiceWPM = pVoiceInfo->Rate;
  267. // m_PitchRange = pVoiceInfo->PitchRange;
  268. m_VoiceWPM = 180;
  269. m_PitchRange = PitchInfo.Range;
  270. m_RateRatio_API = m_RateRatio_PROSODY = 1.0f;
  271. m_fNewPhoneSet = fNewPhoneSet;
  272. return hr;
  273. } /* CFrontend::Init */
  274. static ULONG IPA_to_Allo( WCHAR* pSrc, ALLO_CODE* pDest )
  275. {
  276. ULONG iIpa, iAllo, i;
  277. ULONG gotMatch; // for debugging
  278. iIpa = iAllo = 0;
  279. while( pSrc[iIpa] > 0 )
  280. {
  281. gotMatch = false;
  282. //-----------------------------------------
  283. // ...then search for single word IPA's
  284. //-----------------------------------------
  285. for( i = 0; i < NUMBER_OF_ALLO; i++ )
  286. {
  287. if( pSrc[iIpa] == g_IPAToAllo[i] )
  288. {
  289. pDest[iAllo] = (ALLO_CODE)i;
  290. gotMatch = true;
  291. break;
  292. }
  293. }
  294. if( gotMatch )
  295. {
  296. iAllo++;
  297. }
  298. /*else
  299. {
  300. // Should NEVER get here. Unsupported IPA unicode!
  301. // Ignore it and go on.
  302. }*/
  303. //----------------------------------
  304. // Clip at max length
  305. //----------------------------------
  306. if( iAllo >= (SP_MAX_PRON_LENGTH-1) )
  307. {
  308. iAllo = SP_MAX_PRON_LENGTH-1;
  309. break;
  310. }
  311. iIpa++;
  312. }
  313. return iAllo;
  314. }
  315. /*****************************************************************************
  316. * CFrontend::AlloToUnit *
  317. *-----------------------*
  318. * Description:
  319. * Transform ALLO stream into backend UNIT stream+++
  320. *
  321. ********************************************************************** MC ***/
  322. #ifdef USE_VOICEDATAOBJ
  323. HRESULT CFrontend::AlloToUnit( CAlloList *pAllos, UNITINFO *pu )
  324. {
  325. SPDBG_FUNC( "CFrontend::AlloToUnit" );
  326. bool bFirstPass;
  327. long msPhon, attr;
  328. ULONG numOfCells;
  329. CAlloCell *pCurCell, *pNextCell;
  330. HRESULT hr = S_OK;
  331. bFirstPass = true;
  332. numOfCells = pAllos->GetCount();
  333. pCurCell = pAllos->GetHeadCell();
  334. pNextCell = pAllos->GetNextCell();
  335. while( pCurCell )
  336. {
  337. //--------------------------------------
  338. // Get next allo ID
  339. //--------------------------------------
  340. if( pNextCell )
  341. {
  342. pu->NextAlloID = (USHORT)pNextCell->m_allo;
  343. }
  344. else
  345. {
  346. pu->NextAlloID = _SIL_;
  347. }
  348. //--------------------------------------
  349. // Convert to Whistler phon code
  350. //--------------------------------------
  351. attr = 0;
  352. if( pCurCell->m_ctrlFlags & PRIMARY_STRESS )
  353. {
  354. attr |= ALLO_IS_STRESSED;
  355. }
  356. hr = m_pVoiceDataObj->AlloToUnit( (short)pCurCell->m_allo, attr, &msPhon );
  357. if( FAILED(hr) )
  358. {
  359. //------------------------
  360. // allo ID is invalid
  361. //------------------------
  362. break;
  363. }
  364. else
  365. {
  366. pu->PhonID = msPhon;
  367. pu->AlloID = (USHORT)pCurCell->m_allo;
  368. pu->flags = 0;
  369. pu->AlloFeatures = 0;
  370. pu->ctrlFlags = pCurCell->m_ctrlFlags;
  371. //--------------------------------------
  372. // Flag WORD boundary
  373. //--------------------------------------
  374. if( pCurCell->m_ctrlFlags & WORD_START )
  375. {
  376. pu->flags |= WORD_START_FLAG;
  377. //----------------------------------------------
  378. // Remember source word position and length
  379. //----------------------------------------------
  380. pu->srcPosition = pCurCell->m_SrcPosition;
  381. pu->srcLen = pCurCell->m_SrcLen;
  382. }
  383. //----------------------------------------------------
  384. // Flag SENTENCE boundary on 1st displayable word
  385. //----------------------------------------------------
  386. if( bFirstPass && (pCurCell->m_SentenceLen > 0) )
  387. {
  388. bFirstPass = false;
  389. pu->flags |= SENT_START_FLAG;
  390. //----------------------------------------------
  391. // Remember source word position and length
  392. //----------------------------------------------
  393. pu->sentencePosition = pCurCell->m_SentencePosition;
  394. pu->sentenceLen = pCurCell->m_SentenceLen;
  395. }
  396. pu->nKnots = KNOTS_PER_PHON;
  397. /*for( k = 0; k < pu->nKnots; k++ )
  398. {
  399. pu->pTime[k] = pCurCell->m_ftTime[k] * m_SampleRate;
  400. pu->pF0[k] = pCurCell->m_ftPitch[k];
  401. pu->pAmp[k] = pu->ampRatio;
  402. }*/
  403. //----------------------------
  404. // Controls and events
  405. //----------------------------
  406. pu->user_Volume = pCurCell->m_user_Volume;
  407. pu->pBMObj = (void*)pCurCell->m_pBMObj;
  408. pCurCell->m_pBMObj = NULL;
  409. //----------------------------------------
  410. // Pass features for viseme event
  411. //----------------------------------------
  412. if( pCurCell->m_ctrlFlags & PRIMARY_STRESS )
  413. {
  414. pu->AlloFeatures |= SPVFEATURE_STRESSED;
  415. }
  416. if( pCurCell->m_ctrlFlags & EMPHATIC_STRESS )
  417. {
  418. pu->AlloFeatures |= SPVFEATURE_EMPHASIS;
  419. }
  420. pu->duration = PITCH_BUF_RES;
  421. pu->silenceSource = pCurCell->m_SilenceSource;
  422. pu++;
  423. }
  424. pCurCell = pNextCell;
  425. pNextCell = pAllos->GetNextCell();
  426. }
  427. return hr;
  428. } /* CFrontend::AlloToUnit */
  429. #endif
  430. /*****************************************************************************
  431. * CFrontend::PrepareSpeech *
  432. *--------------------------*
  433. * Description:
  434. * Prepare frontend for new speech
  435. *
  436. ********************************************************************** MC ***/
  437. void CFrontend::PrepareSpeech( IEnumSpSentence* pEnumSent, ISpTTSEngineSite *pOutputSite )
  438. {
  439. SPDBG_FUNC( "CFrontend::PrepareSpeech" );
  440. m_pEnumSent = pEnumSent;
  441. m_SpeechState = SPEECH_CONTINUE;
  442. m_CurUnitIndex = m_unitCount = 0;
  443. m_HasSpeech = false;
  444. m_pOutputSite = pOutputSite;
  445. m_fInQuoteProsody = m_fInParenProsody = false;
  446. m_CurPitchOffs = 0;
  447. m_CurPitchRange = 1.0;
  448. } /* CFrontend::PrepareSpeech */
  449. /*****************************************************************************
  450. * IsTokenPunct *
  451. *--------------*
  452. * Description:
  453. * Return TRUE if char is , . ! or ?
  454. *
  455. ********************************************************************** MC ***/
  456. bool fIsPunctuation( TTSSentItem Item )
  457. {
  458. SPDBG_FUNC( "IsTokenPunct" );
  459. return ( Item.pItemInfo->Type == eCOMMA ||
  460. Item.pItemInfo->Type == eSEMICOLON ||
  461. Item.pItemInfo->Type == eCOLON ||
  462. Item.pItemInfo->Type == ePERIOD ||
  463. Item.pItemInfo->Type == eQUESTION ||
  464. Item.pItemInfo->Type == eEXCLAMATION ||
  465. Item.pItemInfo->Type == eHYPHEN );
  466. } /* fIsPunctuation */
  467. /*****************************************************************************
  468. * CFrontend::ToBISymbols *
  469. *------------------------*
  470. * Description:
  471. * Label each word with ToBI prosody notation+++
  472. *
  473. ********************************************************************** MC ***/
  474. HRESULT CFrontend::ToBISymbols()
  475. {
  476. SPDBG_FUNC( "CFrontend::ToBISymbols" );
  477. TOBI_PHRASE *pTPhrase;
  478. long i, cPhrases;
  479. PROSODY_POS prevPOS, curPOS;
  480. bool possible_YNQ = false;
  481. long cTok;
  482. CFEToken *pTok, *pPrevTok, *pAuxTok;
  483. bool hasEmph = false;
  484. SPLISTPOS listPos;
  485. //----------------------------------
  486. // Get memory for phrase array
  487. //----------------------------------
  488. pAuxTok = NULL; // To quiet the compiler
  489. cTok = m_TokList.GetCount();
  490. if( cTok )
  491. {
  492. pTPhrase = new TOBI_PHRASE[cTok]; // worse case: each token is a phrase
  493. if( pTPhrase )
  494. {
  495. //---------------------------------------------
  496. // Find sub-phrases from POS
  497. // For now, detect function/content boundaries
  498. //---------------------------------------------
  499. hasEmph = false;
  500. cPhrases = 0;
  501. i = 0;
  502. listPos = m_TokList.GetHeadPosition();
  503. pTok = m_TokList.GetNext( listPos );
  504. prevPOS = pTok->m_posClass;
  505. while( pTok->phon_Str[0] == _SIL_ )
  506. {
  507. if( i >= (cTok-1) )
  508. {
  509. break;
  510. }
  511. i++;
  512. if( listPos != NULL )
  513. {
  514. pTok = m_TokList.GetNext( listPos );
  515. }
  516. }
  517. if( pTok->m_posClass == POS_AUX )
  518. {
  519. //---------------------------------
  520. // Could be a yes/no question
  521. //---------------------------------
  522. possible_YNQ = true;
  523. pAuxTok = pTok;
  524. }
  525. pTPhrase[cPhrases].start = i;
  526. for( ; i < cTok; i++ )
  527. {
  528. curPOS = pTok->m_posClass;
  529. if( (curPOS != prevPOS) && (pTok->phon_Str[0] != _SIL_) )
  530. {
  531. pTPhrase[cPhrases].posClass = prevPOS;
  532. pTPhrase[cPhrases].end = i-1;
  533. cPhrases++;
  534. pTPhrase[cPhrases].start = i;
  535. prevPOS = curPOS;
  536. }
  537. if( pTok->user_Emph > 0 )
  538. {
  539. hasEmph = true;
  540. }
  541. if( listPos != NULL )
  542. {
  543. pTok = m_TokList.GetNext( listPos );
  544. }
  545. }
  546. //-------------------------------
  547. // Complete last phrase
  548. //-------------------------------
  549. pTPhrase[cPhrases].posClass = prevPOS;
  550. pTPhrase[cPhrases].end = i-1;
  551. cPhrases++;
  552. for( i = 0; i < cPhrases; i++ )
  553. {
  554. //-------------------------------------------------------
  555. // Sequence of function words, place a low tone
  556. // on the LAST word in a func sequence,
  557. // if there are more than 1 words in the sequence.
  558. //-------------------------------------------------------
  559. if( ((pTPhrase[i].posClass == POS_FUNC) || (pTPhrase[i].posClass == POS_AUX)) &&
  560. (pTPhrase[i].end - pTPhrase[i].start) )
  561. {
  562. pTok = (CFEToken*)m_TokList.GetAt( m_TokList.FindIndex( pTPhrase[i].end ));
  563. if( pTok->m_Accent == K_NOACC )
  564. {
  565. pTok->m_Accent = K_LSTAR;
  566. pTok->m_Accent_Prom = 2;
  567. pTok->m_AccentSource = ACC_FunctionSeq;
  568. }
  569. }
  570. //-------------------------------------------------------
  571. // Sequence of content words, place a high or
  572. // rising tone, of random prominence,
  573. // on the FIRST word in the content sequence
  574. //-------------------------------------------------------
  575. else if ( ((pTPhrase[i].posClass == POS_CONTENT) || (pTPhrase[i].posClass == POS_UNK)) )
  576. {
  577. pTok = (CFEToken*)m_TokList.GetAt( m_TokList.FindIndex( pTPhrase[i].start ));
  578. if( pTok->m_Accent == K_NOACC )
  579. {
  580. pTok->m_Accent = K_HSTAR;
  581. pTok->m_Accent_Prom = rand() % 5;
  582. pTok->m_AccentSource = ACC_ContentSeq;
  583. }
  584. }
  585. }
  586. delete pTPhrase;
  587. //-----------------------------------------
  588. // Now, insert the BOUNDARY tags
  589. //-----------------------------------------
  590. listPos = m_TokList.GetHeadPosition();
  591. pPrevTok = m_TokList.GetNext( listPos );
  592. for( i = 1; i < cTok; i++ )
  593. {
  594. pTok = m_TokList.GetNext( listPos );
  595. //--------------------------------
  596. // Place a terminal boundary
  597. //--------------------------------
  598. if( pTok->m_TuneBoundaryType != NULL_BOUNDARY )
  599. {
  600. switch( pTok->m_TuneBoundaryType )
  601. {
  602. case YN_QUEST_BOUNDARY:
  603. {
  604. pPrevTok->m_Accent = K_LSTAR;
  605. pPrevTok->m_Accent_Prom = 10;
  606. pPrevTok->m_Boundary = K_HMINUSHPERC;
  607. pPrevTok->m_Boundary_Prom = 10;
  608. //-- Diagnostic
  609. if( pPrevTok->m_AccentSource == ACC_NoSource )
  610. {
  611. pPrevTok->m_AccentSource = ACC_YNQuest;
  612. }
  613. //-- Diagnostic
  614. if( pPrevTok->m_BoundarySource == BND_NoSource )
  615. {
  616. pPrevTok->m_BoundarySource = BND_YNQuest;
  617. }
  618. //-------------------------------------------------------
  619. // Accent an aux verb in initial position (possible ynq)
  620. //-------------------------------------------------------
  621. if( possible_YNQ )
  622. {
  623. pAuxTok->m_Accent = K_HSTAR;
  624. pAuxTok->m_Accent_Prom = 5;
  625. pAuxTok->m_AccentSource = ACC_InitialVAux;
  626. }
  627. }
  628. break;
  629. case WH_QUEST_BOUNDARY:
  630. case DECLAR_BOUNDARY:
  631. case EXCLAM_BOUNDARY:
  632. {
  633. if (pPrevTok->m_posClass == POS_CONTENT)
  634. {
  635. pPrevTok->m_Accent = K_HSTAR;
  636. pPrevTok->m_Accent_Prom = 4;
  637. //-- Diagnostic
  638. if( pPrevTok->m_AccentSource == ACC_NoSource )
  639. {
  640. pPrevTok->m_AccentSource = ACC_Period;
  641. }
  642. }
  643. pPrevTok->m_Boundary = K_LMINUSLPERC;
  644. pPrevTok->m_Boundary_Prom = 10;
  645. //--- Diagnostic
  646. if( pPrevTok->m_BoundarySource == BND_NoSource )
  647. {
  648. pPrevTok->m_BoundarySource = BND_Period;
  649. }
  650. }
  651. break;
  652. case PHRASE_BOUNDARY:
  653. {
  654. if (pPrevTok->m_posClass == POS_CONTENT)
  655. {
  656. pPrevTok->m_Accent = K_LHSTAR;
  657. pPrevTok->m_Accent_Prom = 10;
  658. //-- Diagnostic
  659. if( pPrevTok->m_AccentSource == ACC_NoSource )
  660. {
  661. pPrevTok->m_AccentSource = ACC_Comma;
  662. }
  663. }
  664. pPrevTok->m_Boundary = K_LMINUSHPERC;
  665. pPrevTok->m_Boundary_Prom = 5;
  666. //-- Diagnostic
  667. if( pPrevTok->m_BoundarySource == BND_NoSource )
  668. {
  669. pPrevTok->m_BoundarySource = BND_Comma;
  670. }
  671. }
  672. break;
  673. case NUMBER_BOUNDARY:
  674. {
  675. pPrevTok->m_Boundary = K_LMINUSHPERC;
  676. pPrevTok->m_Boundary_Prom = 5;
  677. //-- Diagnostic
  678. if( pPrevTok->m_BoundarySource == BND_NoSource )
  679. {
  680. pPrevTok->m_BoundarySource = BND_NumberTemplate;
  681. }
  682. }
  683. break;
  684. default:
  685. {
  686. // Use comma for all other boundaries
  687. if (pPrevTok->m_posClass == POS_CONTENT)
  688. {
  689. pPrevTok->m_Accent = K_LHSTAR;
  690. pPrevTok->m_Accent_Prom = 10;
  691. //-- Diagnostic
  692. if( pPrevTok->m_AccentSource == ACC_NoSource )
  693. {
  694. pPrevTok->m_AccentSource = pTok->m_AccentSource;
  695. }
  696. }
  697. pPrevTok->m_Boundary = K_LMINUSHPERC;
  698. pPrevTok->m_Boundary_Prom = 5;
  699. //-- Diagnostic
  700. if( pPrevTok->m_BoundarySource == BND_NoSource )
  701. {
  702. pPrevTok->m_BoundarySource = pTok->m_BoundarySource;
  703. }
  704. }
  705. break;
  706. }
  707. }
  708. pPrevTok = pTok;
  709. }
  710. //--------------------------------------------
  711. // Loop through each word and increase
  712. // pitch prominence if EMPHASIZED and
  713. // decrease prominence for all others
  714. //--------------------------------------------
  715. if( hasEmph )
  716. {
  717. SPLISTPOS listPos;
  718. pPrevTok = NULL;
  719. listPos = m_TokList.GetHeadPosition();
  720. while( listPos )
  721. {
  722. pTok = m_TokList.GetNext( listPos );
  723. //------------------------------
  724. // Is this word emphasized?
  725. //------------------------------
  726. if( pTok->user_Emph > 0 )
  727. {
  728. //------------------------------
  729. // Add my clever H*+L*� tag
  730. //------------------------------
  731. pTok->m_Accent = K_HSTARLSTAR;
  732. pTok->m_Accent_Prom = 10;
  733. pTok->m_Boundary = K_NOBND; // Delete any boundary tag here...
  734. if( pPrevTok )
  735. {
  736. pPrevTok->m_Boundary = K_NOBND; // ...or before
  737. }
  738. }
  739. else
  740. {
  741. //-----------------------------------
  742. // Is non-emphasized word accented?
  743. //-----------------------------------
  744. if( (pTok->m_Accent != K_NOACC) && (pTok->m_Accent_Prom > 5) )
  745. {
  746. //------------------------------
  747. // Then clip its prominence at 5
  748. //------------------------------
  749. pTok->m_Accent_Prom = 5;
  750. }
  751. //------------------------------
  752. // Is it a boundary?
  753. //------------------------------
  754. /*if( (pTok->m_Boundary != K_NOBND) && (pTok->m_Boundary_Prom > 5) )
  755. {
  756. //------------------------------
  757. // Then clip its prominence at 5
  758. //------------------------------
  759. pTok->m_Boundary_Prom = 5;
  760. }*/
  761. }
  762. pPrevTok = pTok;
  763. }
  764. }
  765. }
  766. }
  767. return S_OK;
  768. } /* ToBISymbols */
  769. /*****************************************************************************
  770. * CFrontend::TokensToAllo *
  771. *------------------------*
  772. * Description:
  773. * Transform TOKENS into ALLOS
  774. *
  775. ********************************************************************** MC ***/
  776. HRESULT CFrontend::TokensToAllo( CFETokenList *pTokList, CAlloList *pAllo )
  777. {
  778. SPDBG_FUNC( "CFrontend::TokToAllo" );
  779. CAlloCell *pLastCell;
  780. long i;
  781. long cTok;
  782. CFEToken *pCurToken, *pNextToken, *pPrevTok;
  783. SPLISTPOS listPos;
  784. pLastCell = pAllo->GetTailCell(); // Get end (silence)
  785. if( pLastCell )
  786. {
  787. pPrevTok = NULL;
  788. listPos = pTokList->GetHeadPosition();
  789. pCurToken = pTokList->GetNext( listPos );
  790. cTok = pTokList->GetCount();
  791. for( i = 0; i < cTok; i++ )
  792. {
  793. //----------------------------
  794. // Get NEXT word
  795. //----------------------------
  796. if( i < (cTok -1) )
  797. {
  798. pNextToken = pTokList->GetNext( listPos );
  799. }
  800. else
  801. {
  802. pNextToken = NULL;
  803. }
  804. if( pAllo->WordToAllo( pPrevTok, pCurToken, pNextToken, pLastCell ) )
  805. {
  806. m_HasSpeech = true;
  807. }
  808. //----------------------------
  809. // Bump the pipeline
  810. //----------------------------
  811. pPrevTok = pCurToken;
  812. pCurToken = pNextToken;
  813. }
  814. }
  815. return S_OK;
  816. } /* CFrontend::TokensToAllo */
  817. /*****************************************************************************
  818. * CFrontend::GetItemControls *
  819. *----------------------------*
  820. * Description:
  821. * Set user control values from Sent Enum item.
  822. ********************************************************************** MC ***/
  823. void CFrontend::GetItemControls( const SPVSTATE* pXmlState, CFEToken* pToken )
  824. {
  825. SPDBG_FUNC( "CFrontend::GetItemControls" );
  826. pToken->user_Volume = pXmlState->Volume;
  827. pToken->user_Rate = pXmlState->RateAdj;
  828. pToken->user_Pitch = pXmlState->PitchAdj.MiddleAdj;
  829. pToken->user_Emph = pXmlState->EmphAdj;
  830. pToken->m_DurScale = CntrlToRatio( pToken->user_Rate );
  831. if( (pToken->m_DurScale * m_RateRatio_API * m_RateRatio_PROSODY)
  832. < DISCRETE_BKPT )
  833. {
  834. //-- If the total rate is low enough, insert breaks between words
  835. pToken->m_TermSil = 0.050f /
  836. (pToken->m_DurScale * m_RateRatio_API * m_RateRatio_PROSODY);
  837. pToken->m_DurScale = DISCRETE_BKPT;
  838. }
  839. else
  840. {
  841. pToken->m_TermSil = 0;
  842. }
  843. } /* CFrontend::GetItemControls */
  844. /*****************************************************************************
  845. * CFrontend::GetPOSClass *
  846. *------------------------*
  847. * Description:
  848. * Transform SAPI POS code to func/content/aux class.
  849. ********************************************************************** MC ***/
  850. PROSODY_POS CFrontend::GetPOSClass( ENGPARTOFSPEECH sapiPOS )
  851. {
  852. SPDBG_FUNC( "CFrontend::GetPOSClass" );
  853. PROSODY_POS posClass;
  854. posClass = POS_UNK;
  855. switch( sapiPOS )
  856. {
  857. case MS_Noun:
  858. case MS_Verb:
  859. case MS_Adj:
  860. case MS_Adv:
  861. case MS_Interjection:
  862. {
  863. posClass = POS_CONTENT;
  864. break;
  865. }
  866. case MS_VAux:
  867. {
  868. posClass = POS_AUX;
  869. break;
  870. }
  871. case MS_Modifier:
  872. case MS_Function:
  873. case MS_Interr:
  874. case MS_Pron:
  875. case MS_ObjPron:
  876. case MS_SubjPron:
  877. case MS_RelPron:
  878. case MS_Conj:
  879. case MS_CConj:
  880. case MS_Det:
  881. case MS_Contr:
  882. case MS_Prep:
  883. {
  884. posClass = POS_FUNC;
  885. break;
  886. }
  887. }
  888. return posClass;
  889. } /* CFrontend::GetPOSClass */
  890. #define QUOTE_HESITATION 100 // Number of msec
  891. #define PAREN_HESITATION 100 // Number of msec
  892. #define PAREN_HESITATION_TAIL 100 // Number of msec
  893. #define EMPH_HESITATION 1 // Number of msec
  894. /*****************************************************************************
  895. * CFrontend::StateQuoteProsody *
  896. *------------------------------*
  897. * Description:
  898. *
  899. ********************************************************************** MC ***/
  900. bool CFrontend::StateQuoteProsody( CFEToken *pWordTok, TTSSentItem *pSentItem, bool fInsertSil )
  901. {
  902. SPDBG_FUNC( "CFrontend::StateQuoteProsody" );
  903. bool result = false;
  904. if( !m_fInParenProsody )
  905. {
  906. if( m_fInQuoteProsody )
  907. {
  908. //------------------------------
  909. // Stop quote prosody
  910. //------------------------------
  911. m_fInQuoteProsody = false;
  912. m_CurPitchOffs = 0.0f;
  913. m_CurPitchRange = 1.0f;
  914. if( fInsertSil )
  915. {
  916. (void)InsertSilenceAtTail( pWordTok, pSentItem, QUOTE_HESITATION );
  917. pWordTok->m_SilenceSource = SIL_QuoteEnd;
  918. }
  919. }
  920. else
  921. {
  922. //------------------------------
  923. // Begin quote prosody
  924. //------------------------------
  925. m_fInQuoteProsody = true;
  926. m_CurPitchOffs = 0.1f;
  927. m_CurPitchRange = 1.25f;
  928. if( fInsertSil )
  929. {
  930. (void)InsertSilenceAtTail( pWordTok, pSentItem, QUOTE_HESITATION );
  931. pWordTok->m_SilenceSource = SIL_QuoteStart;
  932. }
  933. }
  934. result = true;
  935. }
  936. return result;
  937. } /* CFrontend::StateQuoteProsody */
  938. /*****************************************************************************
  939. * CFrontend::StartParenProsody *
  940. *------------------------------*
  941. * Description:
  942. *
  943. ********************************************************************** MC ***/
  944. bool CFrontend::StartParenProsody( CFEToken *pWordTok, TTSSentItem *pSentItem, bool fInsertSil )
  945. {
  946. SPDBG_FUNC( "CFrontend::StartParenProsody" );
  947. bool result = false;
  948. if( (!m_fInParenProsody) && (!m_fInQuoteProsody) )
  949. {
  950. m_CurPitchOffs = -0.2f;
  951. m_CurPitchRange = 0.75f;
  952. m_fInParenProsody = true;
  953. m_RateRatio_PROSODY = 1.25f;
  954. if( fInsertSil )
  955. {
  956. (void)InsertSilenceAtTail( pWordTok, pSentItem, PAREN_HESITATION );
  957. pWordTok->m_SilenceSource = SIL_ParenStart;
  958. }
  959. result = true;
  960. }
  961. return result;
  962. } /* CFrontend::StartParenProsody */
  963. /*****************************************************************************
  964. * CFrontend::EndParenProsody *
  965. *----------------------------*
  966. * Description:
  967. *
  968. ********************************************************************** MC ***/
  969. bool CFrontend::EndParenProsody( CFEToken *pWordTok, TTSSentItem *pSentItem, bool fInsertSil )
  970. {
  971. SPDBG_FUNC( "CFrontend::EndParenProsody" );
  972. bool result = false;
  973. if( m_fInParenProsody )
  974. {
  975. m_fInParenProsody = false;
  976. m_CurPitchOffs = 0.0f;
  977. m_CurPitchRange = 1.0f;
  978. m_RateRatio_PROSODY = 1.0f;
  979. if( fInsertSil )
  980. {
  981. (void)InsertSilenceAtTail( pWordTok, pSentItem, PAREN_HESITATION_TAIL );
  982. pWordTok->m_SilenceSource = SIL_ParenStart;
  983. }
  984. result = true;
  985. }
  986. return result;
  987. } /* CFrontend::EndParenProsody */
  988. /*****************************************************************************
  989. * CFrontend::InsertSilenceAtTail *
  990. *--------------------------------*
  991. * Description:
  992. *
  993. ********************************************************************** MC ***/
  994. SPLISTPOS CFrontend::InsertSilenceAtTail( CFEToken *pWordTok, TTSSentItem *pSentItem, long msec )
  995. {
  996. SPDBG_FUNC( "CFrontend::InsertSilenceAtTail" );
  997. if( msec > 0 )
  998. {
  999. pWordTok->user_Break = msec;
  1000. }
  1001. pWordTok->phon_Len = 1;
  1002. pWordTok->phon_Str[0] = _SIL_;
  1003. pWordTok->srcPosition = pSentItem->ulItemSrcOffset;
  1004. pWordTok->srcLen = pSentItem->ulItemSrcLen;
  1005. pWordTok->tokStr[0] = 0; // There's no orth for Break
  1006. pWordTok->tokLen = 0;
  1007. pWordTok->m_PitchBaseOffs = m_CurPitchOffs;
  1008. pWordTok->m_PitchRangeScale = m_CurPitchRange;
  1009. pWordTok->m_ProsodyDurScale = m_RateRatio_PROSODY;
  1010. //----------------------------------
  1011. // Advance to next token
  1012. //----------------------------------
  1013. return m_TokList.AddTail( pWordTok );
  1014. } /* CFrontend::InsertSilenceAtTail */
  1015. /*****************************************************************************
  1016. * CFrontend::InsertSilenceAfterPos *
  1017. *-----------------------------------*
  1018. * Description:
  1019. * Insert silence token AFTER 'position'
  1020. *
  1021. ********************************************************************** MC ***/
  1022. SPLISTPOS CFrontend::InsertSilenceAfterPos( CFEToken *pWordTok, SPLISTPOS position )
  1023. {
  1024. SPDBG_FUNC( "CFrontend::InsertSilenceAfterPos" );
  1025. pWordTok->phon_Len = 1;
  1026. pWordTok->phon_Str[0] = _SIL_;
  1027. pWordTok->srcPosition = 0;
  1028. pWordTok->srcLen = 0;
  1029. pWordTok->tokStr[0] = '+'; // punctuation
  1030. pWordTok->tokStr[1] = 0; // delimiter
  1031. pWordTok->tokLen = 1;
  1032. pWordTok->m_PitchBaseOffs = m_CurPitchOffs;
  1033. pWordTok->m_PitchRangeScale = m_CurPitchRange;
  1034. pWordTok->m_ProsodyDurScale = m_RateRatio_PROSODY;
  1035. pWordTok->m_DurScale = 0;
  1036. //----------------------------------
  1037. // Advance to next token
  1038. //----------------------------------
  1039. return m_TokList.InsertAfter( position, pWordTok );
  1040. } /* CFrontend::InsertSilenceAfterPos */
  1041. /*****************************************************************************
  1042. * CFrontend::InsertSilenceBeforePos *
  1043. *------------------------------------*
  1044. * Description:
  1045. * Insert silence token BEFORE 'position'
  1046. *
  1047. ********************************************************************** MC ***/
  1048. SPLISTPOS CFrontend::InsertSilenceBeforePos( CFEToken *pWordTok, SPLISTPOS position )
  1049. {
  1050. SPDBG_FUNC( "CFrontend::InsertSilenceBeforePos" );
  1051. pWordTok->phon_Len = 1;
  1052. pWordTok->phon_Str[0] = _SIL_;
  1053. pWordTok->srcPosition = 0;
  1054. pWordTok->srcLen = 0;
  1055. pWordTok->tokStr[0] = '+'; // punctuation
  1056. pWordTok->tokStr[1] = 0; // delimiter
  1057. pWordTok->tokLen = 1;
  1058. pWordTok->m_PitchBaseOffs = m_CurPitchOffs;
  1059. pWordTok->m_PitchRangeScale = m_CurPitchRange;
  1060. pWordTok->m_ProsodyDurScale = m_RateRatio_PROSODY;
  1061. pWordTok->m_DurScale = 0;
  1062. //----------------------------------
  1063. // Advance to next token
  1064. //----------------------------------
  1065. return m_TokList.InsertBefore( position, pWordTok );
  1066. } /* CFrontend::InsertSilenceBeforePos */
  1067. #define K_ACCENT_PROM ((rand() % 4) + 4)
  1068. #define K_DEACCENT_PROM 5
  1069. #define K_ACCENT K_HSTAR
  1070. #define K_DEACCENT K_NOACC
  1071. /*****************************************************************************
  1072. * CFrontend::ProsodyTemplates *
  1073. *-----------------------------*
  1074. * Description:
  1075. * Call prosody template function for supported item types.
  1076. *
  1077. ********************************************************************** MC ***/
  1078. void CFrontend::ProsodyTemplates( SPLISTPOS clusterPos, TTSSentItem *pSentItem )
  1079. {
  1080. SPDBG_FUNC( "CFrontend::ProsodyTemplates" );
  1081. long cWordCount;
  1082. CFEToken *pClusterTok;
  1083. switch( pSentItem->pItemInfo->Type )
  1084. {
  1085. //---------------------------------------
  1086. // Numbers
  1087. //---------------------------------------
  1088. case eNUM_ROMAN_NUMERAL:
  1089. case eNUM_ROMAN_NUMERAL_ORDINAL:
  1090. {
  1091. if ( ( (TTSRomanNumeralItemInfo*) pSentItem->pItemInfo )->pNumberInfo->Type != eDATE_YEAR )
  1092. {
  1093. if ( ((TTSNumberItemInfo*)((TTSRomanNumeralItemInfo*)pSentItem->pItemInfo)->pNumberInfo)->pIntegerPart )
  1094. {
  1095. DoIntegerTemplate( &clusterPos,
  1096. (TTSNumberItemInfo*)((TTSRomanNumeralItemInfo*)pSentItem->pItemInfo)->pNumberInfo,
  1097. pSentItem->ulNumWords );
  1098. }
  1099. if ( ((TTSNumberItemInfo*)((TTSRomanNumeralItemInfo*)pSentItem->pItemInfo)->pNumberInfo)->pDecimalPart )
  1100. {
  1101. DoNumByNumTemplate( &clusterPos,
  1102. ((TTSNumberItemInfo*)((TTSRomanNumeralItemInfo*)pSentItem->pItemInfo)->pNumberInfo)->pDecimalPart->ulNumDigits );
  1103. }
  1104. }
  1105. }
  1106. break;
  1107. case eNUM_CARDINAL:
  1108. case eNUM_DECIMAL:
  1109. case eNUM_ORDINAL:
  1110. case eNUM_MIXEDFRACTION:
  1111. {
  1112. if ( ( (TTSNumberItemInfo*) pSentItem->pItemInfo )->pIntegerPart )
  1113. {
  1114. cWordCount = DoIntegerTemplate( &clusterPos,
  1115. (TTSNumberItemInfo*) pSentItem->pItemInfo,
  1116. pSentItem->ulNumWords );
  1117. }
  1118. if( ( (TTSNumberItemInfo*) pSentItem->pItemInfo )->pDecimalPart )
  1119. {
  1120. //-----------------------------------------
  1121. // Skip "point" string...
  1122. //-----------------------------------------
  1123. (void) m_TokList.GetNext( clusterPos );
  1124. //-----------------------------------------
  1125. // ...and do single digit prosody
  1126. //-----------------------------------------
  1127. DoNumByNumTemplate( &clusterPos,
  1128. ( (TTSNumberItemInfo*) pSentItem->pItemInfo )->pDecimalPart->ulNumDigits );
  1129. }
  1130. if ( ( (TTSNumberItemInfo*) pSentItem->pItemInfo )->pFractionalPart )
  1131. {
  1132. //-----------------------------------------
  1133. // Skip "and" string...
  1134. //-----------------------------------------
  1135. pClusterTok = m_TokList.GetNext( clusterPos );
  1136. if( pClusterTok->m_Accent == K_NOACC )
  1137. {
  1138. //--------------------------------------
  1139. // Force POS for "and" to noun
  1140. // so phrasing rules don't kick in!
  1141. //--------------------------------------
  1142. pClusterTok->m_Accent = K_DEACCENT;
  1143. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1144. pClusterTok->POScode = MS_Noun;
  1145. pClusterTok->m_posClass = POS_CONTENT;
  1146. }
  1147. //-----------------------------------------
  1148. // ...and do fraction prosody
  1149. //-----------------------------------------
  1150. cWordCount = DoFractionTemplate( &clusterPos,
  1151. (TTSNumberItemInfo*) pSentItem->pItemInfo,
  1152. pSentItem->ulNumWords );
  1153. }
  1154. }
  1155. break;
  1156. //---------------------------------------
  1157. // Fraction
  1158. //---------------------------------------
  1159. case eNUM_FRACTION:
  1160. {
  1161. cWordCount = DoFractionTemplate( &clusterPos,
  1162. (TTSNumberItemInfo*) pSentItem->pItemInfo,
  1163. pSentItem->ulNumWords );
  1164. }
  1165. break;
  1166. //---------------------------------------
  1167. // Money
  1168. //---------------------------------------
  1169. case eNUM_CURRENCY:
  1170. {
  1171. DoCurrencyTemplate( clusterPos, pSentItem );
  1172. }
  1173. break;
  1174. //---------------------------------------
  1175. // Phone Numbers
  1176. //---------------------------------------
  1177. case eNUM_PHONENUMBER:
  1178. case eNEWNUM_PHONENUMBER:
  1179. {
  1180. DoPhoneNumberTemplate( clusterPos, pSentItem );
  1181. }
  1182. break;
  1183. //---------------------------------------
  1184. // Time-of-Day
  1185. //---------------------------------------
  1186. case eTIMEOFDAY:
  1187. {
  1188. DoTODTemplate( clusterPos, pSentItem );
  1189. }
  1190. break;
  1191. case eELLIPSIS:
  1192. {
  1193. CFEToken *pWordTok;
  1194. pWordTok = new CFEToken;
  1195. if( pWordTok )
  1196. {
  1197. clusterPos = InsertSilenceAtTail( pWordTok, pSentItem, 0 );
  1198. //clusterPos = m_TokList.GetTailPosition( );
  1199. //clusterPos = InsertSilenceAfterPos( pWordTok, clusterPos );
  1200. pWordTok->m_SilenceSource = SIL_Ellipsis;
  1201. pWordTok->m_TuneBoundaryType = ELLIPSIS_BOUNDARY;
  1202. pWordTok->m_BoundarySource = BND_Ellipsis;
  1203. }
  1204. }
  1205. break;
  1206. }
  1207. } /* CFrontend::ProsodyTemplates */
  1208. /*****************************************************************************
  1209. * CFrontend::DoTODTemplate *
  1210. *--------------------------*
  1211. * Description:
  1212. * Prosody template for time-of-day.
  1213. *
  1214. * TODO: Temp kludge - needs more info in TTSTimeOfDayItemInfo
  1215. ********************************************************************** MC ***/
  1216. void CFrontend::DoTODTemplate( SPLISTPOS clusterPos, TTSSentItem *pSentItem )
  1217. {
  1218. SPDBG_FUNC( "CFrontend::DoTODTemplate" );
  1219. TTSTimeOfDayItemInfo *pTOD;
  1220. CFEToken *pWordTok;
  1221. CFEToken *pClusterTok;
  1222. SPLISTPOS curPos, nextPos, prevPos;
  1223. curPos = nextPos = clusterPos;
  1224. pTOD = (TTSTimeOfDayItemInfo*)&pSentItem->pItemInfo->Type;
  1225. // Can't do 24 hr because there's no way to tell
  1226. // if it's 1 or 2 digits (18: vs 23:)
  1227. if( !pTOD->fTwentyFourHour )
  1228. {
  1229. //-------------------------------------
  1230. // Get HOUR token
  1231. //-------------------------------------
  1232. pClusterTok = m_TokList.GetNext( nextPos );
  1233. //-------------------------------------
  1234. // Accent hour
  1235. //-------------------------------------
  1236. pClusterTok->m_Accent = K_ACCENT;
  1237. pClusterTok->m_Accent_Prom = K_ACCENT_PROM;
  1238. pClusterTok->m_AccentSource = ACC_TimeOFDay_HR;
  1239. //---------------------------------
  1240. // Insert SILENCE after hour
  1241. //---------------------------------
  1242. pWordTok = new CFEToken;
  1243. if( pWordTok )
  1244. {
  1245. nextPos = InsertSilenceAfterPos( pWordTok, clusterPos );
  1246. pWordTok->m_SilenceSource = SIL_TimeOfDay_HR;
  1247. pWordTok->m_TuneBoundaryType = NUMBER_BOUNDARY;
  1248. pWordTok->m_BoundarySource = BND_TimeOFDay_HR;
  1249. pWordTok = NULL;
  1250. //----------------------------
  1251. // Skip last digit
  1252. //----------------------------
  1253. if( clusterPos != NULL )
  1254. {
  1255. curPos = nextPos;
  1256. pClusterTok = m_TokList.GetNext( nextPos );
  1257. }
  1258. }
  1259. if( pTOD->fMinutes )
  1260. {
  1261. curPos = nextPos;
  1262. pClusterTok = m_TokList.GetNext( nextPos );
  1263. //-------------------------------------
  1264. // Accent 1st digit for minutes
  1265. //-------------------------------------
  1266. pClusterTok->m_Accent = K_ACCENT;
  1267. pClusterTok->m_Accent_Prom = K_ACCENT_PROM;
  1268. pClusterTok->m_AccentSource = ACC_TimeOFDay_1stMin;
  1269. }
  1270. if( pTOD->fTimeAbbreviation )
  1271. {
  1272. curPos = prevPos = m_TokList.GetTailPosition( );
  1273. pClusterTok = m_TokList.GetPrev( prevPos );
  1274. pWordTok = new CFEToken;
  1275. if( pWordTok )
  1276. {
  1277. prevPos = InsertSilenceBeforePos( pWordTok, prevPos );
  1278. pWordTok->m_SilenceSource = SIL_TimeOfDay_AB;
  1279. pWordTok->m_TuneBoundaryType = TOD_BOUNDARY;
  1280. pWordTok->m_BoundarySource = BND_TimeOFDay_AB;
  1281. pWordTok = NULL;
  1282. //pClusterTok = m_TokList.GetNext( clusterPos );
  1283. //pClusterTok = m_TokList.GetNext( clusterPos );
  1284. }
  1285. //-------------------------------------
  1286. // Accent "M"
  1287. //-------------------------------------
  1288. pClusterTok = m_TokList.GetNext( curPos );
  1289. pClusterTok->m_Accent = K_ACCENT;
  1290. pClusterTok->m_Accent_Prom = K_ACCENT_PROM;
  1291. pClusterTok->m_AccentSource = ACC_TimeOFDay_M;
  1292. }
  1293. }
  1294. } /* CFrontend::DoTODTemplate */
  1295. CFEToken *CFrontend::InsertPhoneSilenceAtSpace( SPLISTPOS *pClusterPos,
  1296. BOUNDARY_SOURCE bndSrc,
  1297. SILENCE_SOURCE silSrc )
  1298. {
  1299. CFEToken *pWordTok;
  1300. SPLISTPOS curPos, nextPos;
  1301. curPos = nextPos = *pClusterPos;
  1302. //---------------------------------
  1303. // Insert SILENCE after area code
  1304. //---------------------------------
  1305. pWordTok = new CFEToken;
  1306. if( pWordTok )
  1307. {
  1308. nextPos = InsertSilenceBeforePos( pWordTok, curPos );
  1309. pWordTok->m_SilenceSource = silSrc;
  1310. pWordTok->m_TuneBoundaryType = PHONE_BOUNDARY;
  1311. pWordTok->m_BoundarySource = bndSrc;
  1312. pWordTok->m_AccentSource = ACC_PhoneBnd_AREA; // @@@@ ???
  1313. pWordTok = NULL;
  1314. //----------------------------
  1315. // Skip last digit
  1316. //----------------------------
  1317. if( nextPos != NULL )
  1318. {
  1319. curPos = nextPos;
  1320. pWordTok = m_TokList.GetNext( nextPos );
  1321. }
  1322. }
  1323. //pWordTok = m_TokList.GetNext( clusterPos );
  1324. //-----------------------------------------
  1325. // Filter and embedded silences
  1326. //-----------------------------------------
  1327. while( (pWordTok->phon_Str[0] == _SIL_) && (nextPos != NULL) )
  1328. {
  1329. curPos = nextPos;
  1330. pWordTok = m_TokList.GetNext( nextPos );
  1331. }
  1332. *pClusterPos = curPos;
  1333. return pWordTok;
  1334. }
  1335. void CFrontend::InsertPhoneSilenceAtEnd( BOUNDARY_SOURCE bndSrc,
  1336. SILENCE_SOURCE silSrc )
  1337. {
  1338. CFEToken *pWordTok;
  1339. SPLISTPOS curPos, nextPos;
  1340. curPos = m_TokList.GetTailPosition( );
  1341. //---------------------------------
  1342. // Insert SILENCE after area code
  1343. //---------------------------------
  1344. pWordTok = new CFEToken;
  1345. if( pWordTok )
  1346. {
  1347. nextPos = InsertSilenceAfterPos( pWordTok, curPos );
  1348. pWordTok->m_SilenceSource = silSrc;
  1349. pWordTok->m_TuneBoundaryType = PHONE_BOUNDARY;
  1350. pWordTok->m_BoundarySource = bndSrc;
  1351. pWordTok->m_AccentSource = ACC_PhoneBnd_AREA; // @@@@ ???
  1352. }
  1353. }
  1354. /*****************************************************************************
  1355. * CFrontend::DoPhoneNumberTemplate *
  1356. *----------------------------------*
  1357. * Description:
  1358. * Prosody template for phone numbers.
  1359. *
  1360. ********************************************************************** MC ***/
  1361. void CFrontend::DoPhoneNumberTemplate( SPLISTPOS clusterPos, TTSSentItem *pSentItem )
  1362. {
  1363. SPDBG_FUNC( "CFrontend::DoPhoneNumberTemplate" );
  1364. TTSPhoneNumberItemInfo *pFone;
  1365. CFEToken *pClusterTok;
  1366. long cWordCount;
  1367. SPLISTPOS curPos, nextPos;
  1368. curPos = nextPos = clusterPos;
  1369. pFone = (TTSPhoneNumberItemInfo*)&pSentItem->pItemInfo->Type;
  1370. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  1371. //
  1372. // COUNTRY CODE
  1373. //
  1374. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  1375. if( pFone->pCountryCode )
  1376. {
  1377. //-------------------------------------
  1378. // Skip "country" and...
  1379. //-------------------------------------
  1380. curPos = nextPos;
  1381. pClusterTok = m_TokList.GetNext( nextPos );
  1382. //-------------------------------------
  1383. // ...skip "code"
  1384. //-------------------------------------
  1385. curPos = nextPos;
  1386. pClusterTok = m_TokList.GetNext( nextPos );
  1387. cWordCount = DoIntegerTemplate( &nextPos,
  1388. pFone->pCountryCode,
  1389. pSentItem->ulNumWords );
  1390. pClusterTok = InsertPhoneSilenceAtSpace( &nextPos, BND_Phone_COUNTRY, SIL_Phone_COUNTRY );
  1391. }
  1392. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  1393. //
  1394. // "One"
  1395. //
  1396. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  1397. if( pFone->fOne )
  1398. {
  1399. //-------------------------------------
  1400. // Skip "One"
  1401. //-------------------------------------
  1402. curPos = nextPos;
  1403. pClusterTok = m_TokList.GetNext( nextPos );
  1404. //-------------------------------------
  1405. // and add silence
  1406. //-------------------------------------
  1407. pClusterTok = InsertPhoneSilenceAtSpace( &nextPos, BND_Phone_ONE, SIL_Phone_ONE );
  1408. }
  1409. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  1410. //
  1411. // AREA CODE
  1412. //
  1413. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  1414. if( pFone->pAreaCode )
  1415. {
  1416. if( (pFone->fIs800) && nextPos )
  1417. {
  1418. //--------------------------
  1419. // Skip digit
  1420. //--------------------------
  1421. curPos = nextPos;
  1422. pClusterTok = m_TokList.GetNext( nextPos );
  1423. //--------------------------
  1424. // Skip "hundred"
  1425. //--------------------------
  1426. curPos = nextPos;
  1427. pClusterTok = m_TokList.GetNext( nextPos );
  1428. if( nextPos )
  1429. {
  1430. pClusterTok = InsertPhoneSilenceAtSpace( &nextPos, BND_Phone_AREA, SIL_Phone_AREA );
  1431. }
  1432. }
  1433. else
  1434. {
  1435. //-------------------------------------
  1436. // Skip "area" and...
  1437. //-------------------------------------
  1438. curPos = nextPos;
  1439. pClusterTok = m_TokList.GetNext( nextPos );
  1440. //-------------------------------------
  1441. // ...skip "code"
  1442. //-------------------------------------
  1443. curPos = nextPos;
  1444. pClusterTok = m_TokList.GetNext( nextPos );
  1445. DoNumByNumTemplate( &nextPos, pFone->pAreaCode->ulNumDigits );
  1446. if( nextPos )
  1447. {
  1448. pClusterTok = InsertPhoneSilenceAtSpace( &nextPos, BND_Phone_AREA, SIL_Phone_AREA );
  1449. }
  1450. }
  1451. }
  1452. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  1453. //
  1454. // Digits
  1455. //
  1456. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  1457. unsigned long i;
  1458. for( i = 0; i < pFone->ulNumGroups; i++ )
  1459. {
  1460. DoNumByNumTemplate( &nextPos, pFone->ppGroups[i]->ulNumDigits );
  1461. if( nextPos )
  1462. {
  1463. pClusterTok = InsertPhoneSilenceAtSpace( &nextPos, BND_Phone_DIGITS, SIL_Phone_DIGITS );
  1464. }
  1465. }
  1466. InsertPhoneSilenceAtEnd( BND_Phone_DIGITS, SIL_Phone_DIGITS );
  1467. } /* CFrontend::DoPhoneNumberTemplate */
  1468. /*****************************************************************************
  1469. * CFrontend::DoCurrencyTemplate *
  1470. *-------------------------------*
  1471. * Description:
  1472. * Prosody template for currency.
  1473. *
  1474. ********************************************************************** MC ***/
  1475. void CFrontend::DoCurrencyTemplate( SPLISTPOS clusterPos, TTSSentItem *pSentItem )
  1476. {
  1477. SPDBG_FUNC( "CFrontend::DoCurrencyTemplate" );
  1478. TTSCurrencyItemInfo *pMoney;
  1479. CFEToken *pWordTok;
  1480. CFEToken *pClusterTok = NULL;
  1481. long cWordCount;
  1482. SPLISTPOS curPos, nextPos;
  1483. pMoney = (TTSCurrencyItemInfo*)&pSentItem->pItemInfo->Type;
  1484. curPos = nextPos = clusterPos;
  1485. if( pMoney->pPrimaryNumberPart->Type != eNUM_CARDINAL )
  1486. {
  1487. return;
  1488. }
  1489. cWordCount = DoIntegerTemplate( &nextPos,
  1490. pMoney->pPrimaryNumberPart,
  1491. pSentItem->ulNumWords );
  1492. curPos = nextPos;
  1493. if( cWordCount > 1 )
  1494. {
  1495. if( pMoney->fQuantifier )
  1496. {
  1497. if( nextPos != NULL )
  1498. {
  1499. curPos = nextPos;
  1500. pClusterTok = m_TokList.GetNext( nextPos );
  1501. }
  1502. cWordCount--;
  1503. }
  1504. }
  1505. if( cWordCount > 1 )
  1506. {
  1507. //---------------------------------
  1508. // Insert SILENCE after "dollars"
  1509. //---------------------------------
  1510. pWordTok = new CFEToken;
  1511. if( pWordTok )
  1512. {
  1513. nextPos = InsertSilenceAfterPos( pWordTok, curPos );
  1514. pWordTok->m_SilenceSource = SIL_Currency_DOLLAR;
  1515. pWordTok->m_TuneBoundaryType = NUMBER_BOUNDARY;
  1516. pWordTok->m_BoundarySource = BND_Currency_DOLLAR;
  1517. pWordTok = NULL;
  1518. //----------------------------
  1519. // Skip "dollar(s)"
  1520. //----------------------------
  1521. if( nextPos != NULL )
  1522. {
  1523. curPos = nextPos;
  1524. pClusterTok = m_TokList.GetNext( nextPos );
  1525. }
  1526. }
  1527. if( pMoney->pSecondaryNumberPart != NULL )
  1528. {
  1529. //----------------------------
  1530. // Skip SILENCE
  1531. //----------------------------
  1532. if( nextPos != NULL )
  1533. {
  1534. curPos = nextPos;
  1535. pClusterTok = m_TokList.GetNext( nextPos );
  1536. }
  1537. cWordCount--;
  1538. //----------------------------
  1539. // Skip AND
  1540. //----------------------------
  1541. if( nextPos != NULL )
  1542. {
  1543. curPos = nextPos;
  1544. if( pClusterTok->m_Accent == K_NOACC )
  1545. {
  1546. //--------------------------------------
  1547. // Force POS for "and" to noun
  1548. // so phrasing rules don't kick in!
  1549. //--------------------------------------
  1550. pClusterTok->m_Accent = K_DEACCENT;
  1551. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1552. pClusterTok->POScode = MS_Noun;
  1553. pClusterTok->m_posClass = POS_CONTENT;
  1554. }
  1555. pClusterTok = m_TokList.GetNext( nextPos );
  1556. }
  1557. cWordCount--;
  1558. cWordCount = DoIntegerTemplate( &curPos,
  1559. pMoney->pSecondaryNumberPart,
  1560. cWordCount );
  1561. }
  1562. }
  1563. } /* CFrontend::DoCurrencyTemplate */
  1564. /*****************************************************************************
  1565. * CFrontend::DoNumByNumTemplate *
  1566. *---------------------------------*
  1567. * Description:
  1568. * Prosody template for RIGHT hand side of the decimal point.
  1569. *
  1570. ********************************************************************** MC ***/
  1571. void CFrontend::DoNumByNumTemplate( SPLISTPOS *pClusterPos, long cWordCount )
  1572. {
  1573. SPDBG_FUNC( "CFrontend::DoNumByNumTemplate" );
  1574. CFEToken *pClusterTok;
  1575. SPLISTPOS curPos, nextPos;
  1576. curPos = nextPos = *pClusterPos;
  1577. while( cWordCount > 1 )
  1578. {
  1579. pClusterTok = NULL;
  1580. //-------------------------------------------------------------
  1581. // Right side of decimal point - add H* to every other word
  1582. //-------------------------------------------------------------
  1583. if( nextPos != NULL )
  1584. {
  1585. curPos = nextPos;
  1586. pClusterTok = m_TokList.GetNext( nextPos );
  1587. }
  1588. cWordCount--;
  1589. if( pClusterTok )
  1590. {
  1591. pClusterTok->m_Accent = K_ACCENT;
  1592. pClusterTok->m_Accent_Prom = K_ACCENT_PROM;
  1593. pClusterTok->m_AccentSource = ACC_NumByNum;
  1594. }
  1595. if( nextPos != NULL )
  1596. {
  1597. curPos = nextPos;
  1598. pClusterTok = m_TokList.GetNext( nextPos );
  1599. }
  1600. cWordCount--;
  1601. }
  1602. if( cWordCount > 0 )
  1603. {
  1604. if( nextPos != NULL )
  1605. {
  1606. curPos = nextPos;
  1607. pClusterTok = m_TokList.GetNext( nextPos );
  1608. }
  1609. cWordCount--;
  1610. }
  1611. *pClusterPos = nextPos;
  1612. } /* CFrontend::DoNumByNumTemplate */
  1613. /*****************************************************************************
  1614. * CFrontend::DoFractionTemplate *
  1615. *------------------------------*
  1616. * Description:
  1617. * Prosody template for RIGHT side of the decimal point.
  1618. *
  1619. ********************************************************************** MC ***/
  1620. long CFrontend::DoFractionTemplate( SPLISTPOS *pClusterPos, TTSNumberItemInfo *pNInfo, long cWordCount )
  1621. {
  1622. SPDBG_FUNC( "CFrontend::DoFractionTemplate" );
  1623. CFEToken *pClusterTok;
  1624. TTSFractionItemInfo *pFInfo;
  1625. CFEToken *pWordTok;
  1626. pFInfo = pNInfo->pFractionalPart;
  1627. //--- Do Numerator...
  1628. if ( pFInfo->pNumerator->pIntegerPart )
  1629. {
  1630. cWordCount = DoIntegerTemplate( pClusterPos, pFInfo->pNumerator, cWordCount );
  1631. }
  1632. if( pFInfo->pNumerator->pDecimalPart )
  1633. {
  1634. //-----------------------------------------
  1635. // Skip "point" string...
  1636. //-----------------------------------------
  1637. (void) m_TokList.GetNext( *pClusterPos );
  1638. //-----------------------------------------
  1639. // ...and do single digit prosody
  1640. //-----------------------------------------
  1641. DoNumByNumTemplate( pClusterPos, pFInfo->pNumerator->pDecimalPart->ulNumDigits );
  1642. }
  1643. //--- Special case - a non-standard fraction (e.g. 1/4)
  1644. if( !pFInfo->fIsStandard )
  1645. {
  1646. if( !*pClusterPos )
  1647. {
  1648. *pClusterPos = m_TokList.GetTailPosition( );
  1649. }
  1650. else
  1651. {
  1652. pClusterTok = m_TokList.GetPrev( *pClusterPos );
  1653. }
  1654. }
  1655. pWordTok = new CFEToken;
  1656. if( pWordTok )
  1657. {
  1658. *pClusterPos = InsertSilenceBeforePos( pWordTok, *pClusterPos );
  1659. pWordTok->m_SilenceSource = SIL_Fractions_NUM;
  1660. pWordTok->m_TuneBoundaryType = NUMBER_BOUNDARY;
  1661. pWordTok->m_BoundarySource = BND_Frac_Num;
  1662. pWordTok = NULL;
  1663. //----------------------------
  1664. // Skip numerator
  1665. //----------------------------
  1666. if( *pClusterPos != NULL )
  1667. {
  1668. pClusterTok = m_TokList.GetNext( *pClusterPos );
  1669. }
  1670. }
  1671. //--- Do Denominator...
  1672. if ( pFInfo->pDenominator->pIntegerPart )
  1673. {
  1674. //-----------------------------------------
  1675. // Skip "over" string...
  1676. //-----------------------------------------
  1677. pClusterTok = m_TokList.GetNext( *pClusterPos );
  1678. if( pClusterTok->m_Accent == K_NOACC )
  1679. {
  1680. //--------------------------------------
  1681. // Force POS for "and" to noun
  1682. // so phrasing rules don't kick in!
  1683. //--------------------------------------
  1684. pClusterTok->m_Accent = K_DEACCENT;
  1685. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1686. pClusterTok->POScode = MS_Noun;
  1687. pClusterTok->m_posClass = POS_CONTENT;
  1688. }
  1689. cWordCount = DoIntegerTemplate( pClusterPos, pFInfo->pDenominator, cWordCount );
  1690. }
  1691. if( pFInfo->pDenominator->pDecimalPart )
  1692. {
  1693. //-----------------------------------------
  1694. // Skip "point" string...
  1695. //-----------------------------------------
  1696. (void) m_TokList.GetNext( *pClusterPos );
  1697. //-----------------------------------------
  1698. // ...and do single digit prosody
  1699. //-----------------------------------------
  1700. DoNumByNumTemplate( pClusterPos, pFInfo->pDenominator->pDecimalPart->ulNumDigits );
  1701. }
  1702. return cWordCount;
  1703. } /* CFrontend::DoFractionTemplate */
  1704. /*****************************************************************************
  1705. * CFrontend::DoIntegerTemplate *
  1706. *------------------------------*
  1707. * Description:
  1708. * Prosody template for LEFT hand side of the decimal point.
  1709. *
  1710. ********************************************************************** MC ***/
  1711. long CFrontend::DoIntegerTemplate( SPLISTPOS *pClusterPos, TTSNumberItemInfo *pNInfo, long cWordCount )
  1712. {
  1713. SPDBG_FUNC( "CFrontend::DoIntegerTemplate" );
  1714. long i;
  1715. CFEToken *pClusterTok;
  1716. CFEToken *pWordTok = NULL;
  1717. SPLISTPOS curPos, nextPos;
  1718. //------------------------------------------
  1719. // Special currency hack...sorry
  1720. //------------------------------------------
  1721. if( pNInfo->pIntegerPart->fDigitByDigit )
  1722. {
  1723. DoNumByNumTemplate( pClusterPos, pNInfo->pIntegerPart->ulNumDigits );
  1724. return cWordCount - pNInfo->pIntegerPart->ulNumDigits;
  1725. }
  1726. nextPos = curPos = *pClusterPos;
  1727. pClusterTok = m_TokList.GetNext( nextPos );
  1728. pClusterTok->m_Accent = K_DEACCENT;
  1729. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1730. if( pNInfo->fNegative )
  1731. {
  1732. //---------------------------------
  1733. // Skip "NEGATIVE"
  1734. //---------------------------------
  1735. if( nextPos != NULL )
  1736. {
  1737. curPos = nextPos;
  1738. pClusterTok = m_TokList.GetNext( nextPos );
  1739. pClusterTok->m_Accent = K_DEACCENT;
  1740. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1741. }
  1742. cWordCount--;
  1743. }
  1744. for( i = (pNInfo->pIntegerPart->lNumGroups -1); i >= 0; i-- )
  1745. {
  1746. //------------------------------------
  1747. // Accent 1st digit in group
  1748. //------------------------------------
  1749. pClusterTok->m_Accent = K_ACCENT;
  1750. pClusterTok->m_Accent_Prom = K_ACCENT_PROM;
  1751. pClusterTok->m_AccentSource = ACC_IntegerGroup;
  1752. if( pNInfo->pIntegerPart->Groups[i].fHundreds )
  1753. {
  1754. //---------------------------------
  1755. // Skip "X HUNDRED"
  1756. //---------------------------------
  1757. if( nextPos != NULL )
  1758. {
  1759. curPos = nextPos;
  1760. pClusterTok = m_TokList.GetNext( nextPos );
  1761. if( pClusterTok->m_Accent == K_NOACC )
  1762. {
  1763. pClusterTok->m_Accent = K_DEACCENT;
  1764. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1765. }
  1766. }
  1767. cWordCount--;
  1768. if( nextPos != NULL )
  1769. {
  1770. curPos = nextPos;
  1771. pClusterTok = m_TokList.GetNext( nextPos );
  1772. if( pClusterTok->m_Accent == K_NOACC )
  1773. {
  1774. pClusterTok->m_Accent = K_DEACCENT;
  1775. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1776. }
  1777. }
  1778. cWordCount--;
  1779. }
  1780. if( pNInfo->pIntegerPart->Groups[i].fTens )
  1781. {
  1782. //---------------------------------
  1783. // Skip "X-TY"
  1784. //---------------------------------
  1785. if( nextPos != NULL )
  1786. {
  1787. curPos = nextPos;
  1788. pClusterTok = m_TokList.GetNext( nextPos );
  1789. if( pClusterTok->m_Accent == K_NOACC )
  1790. {
  1791. pClusterTok->m_Accent = K_DEACCENT;
  1792. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1793. }
  1794. }
  1795. cWordCount--;
  1796. }
  1797. if( pNInfo->pIntegerPart->Groups[i].fOnes )
  1798. {
  1799. //---------------------------------
  1800. // Skip "X"
  1801. //---------------------------------
  1802. if( nextPos != NULL )
  1803. {
  1804. curPos = nextPos;
  1805. pClusterTok = m_TokList.GetNext( nextPos );
  1806. if( pClusterTok->m_Accent == K_NOACC )
  1807. {
  1808. pClusterTok->m_Accent = K_DEACCENT;
  1809. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1810. }
  1811. }
  1812. cWordCount--;
  1813. }
  1814. if( pNInfo->pIntegerPart->Groups[i].fQuantifier )
  1815. {
  1816. //---------------------------------
  1817. // Insert SILENCE after quant
  1818. //---------------------------------
  1819. if( pWordTok == NULL )
  1820. {
  1821. pWordTok = new CFEToken;
  1822. }
  1823. if( pWordTok )
  1824. {
  1825. nextPos = InsertSilenceAfterPos( pWordTok, curPos );
  1826. pWordTok->m_SilenceSource = SIL_Integer_Quant;
  1827. pWordTok->m_TuneBoundaryType = NUMBER_BOUNDARY;
  1828. pWordTok->m_BoundarySource = BND_IntegerQuant;
  1829. pWordTok = NULL;
  1830. if( pClusterTok->m_Accent == K_NOACC )
  1831. {
  1832. pClusterTok->m_Accent = K_DEACCENT;
  1833. pClusterTok->m_Accent_Prom = K_DEACCENT_PROM;
  1834. }
  1835. if( nextPos != NULL )
  1836. {
  1837. //------------------------------
  1838. // Skip inserted silence
  1839. //------------------------------
  1840. curPos = nextPos;
  1841. pClusterTok = m_TokList.GetNext( nextPos );
  1842. }
  1843. if( nextPos != NULL )
  1844. {
  1845. //-----------------------------------
  1846. // Skip quantifier string
  1847. //-----------------------------------
  1848. curPos = nextPos;
  1849. pClusterTok = m_TokList.GetNext( nextPos );
  1850. }
  1851. cWordCount--;
  1852. }
  1853. }
  1854. }
  1855. *pClusterPos = curPos;
  1856. return cWordCount;
  1857. } /* CFrontend::DoIntegerTemplate */
  1858. /*****************************************************************************
  1859. * CFrontend::GetSentenceTokens *
  1860. *------------------------------*
  1861. * Description:
  1862. * Collect Senence Enum tokens.
  1863. * Copy tokens into 'm_TokList' and token count into 'm_cNumOfWords'
  1864. * S_FALSE return means no more input sentences.+++
  1865. *
  1866. ********************************************************************** MC ***/
  1867. HRESULT CFrontend::GetSentenceTokens( DIRECTION eDirection )
  1868. {
  1869. SPDBG_FUNC( "CFrontend::GetSentenceTokens" );
  1870. HRESULT eHR = S_OK;
  1871. bool fLastItem = false;
  1872. IEnumSENTITEM *pItemizer;
  1873. TTSSentItem sentItem;
  1874. long tokenIndex;
  1875. CFEToken *pWordTok;
  1876. bool lastWasTerm = false;
  1877. bool lastWasSil = true;
  1878. TUNE_TYPE defaultTune = PHRASE_BOUNDARY;
  1879. long cNumOfItems, cCurItem, cCurWord;
  1880. SPLISTPOS clusterPos, tempPos;
  1881. m_cNumOfWords = 0;
  1882. pWordTok = NULL;
  1883. clusterPos = NULL;
  1884. if ( eDirection == eNEXT )
  1885. {
  1886. eHR = m_pEnumSent->Next( &pItemizer );
  1887. }
  1888. else
  1889. {
  1890. eHR = m_pEnumSent->Previous( &pItemizer );
  1891. }
  1892. if( eHR == S_OK )
  1893. {
  1894. //--------------------------------------------
  1895. // There's still another sentence to speak
  1896. //--------------------------------------------
  1897. tokenIndex = 0;
  1898. CItemList& ItemList = ((CSentItemEnum*)pItemizer)->_GetList();
  1899. cNumOfItems = (ItemList.GetCount()) -1;
  1900. cCurItem = 0;
  1901. //------------------------------------
  1902. // Collect all sentence tokens
  1903. //------------------------------------
  1904. while( (eHR = pItemizer->Next( &sentItem )) == S_OK )
  1905. {
  1906. clusterPos = NULL;
  1907. cCurWord = sentItem.ulNumWords;
  1908. for ( ULONG i = 0; i < sentItem.ulNumWords; i++ )
  1909. {
  1910. //------------------------------
  1911. // Always have a working token
  1912. //------------------------------
  1913. if( pWordTok == NULL )
  1914. {
  1915. pWordTok = new CFEToken;
  1916. }
  1917. if( pWordTok )
  1918. {
  1919. if( sentItem.pItemInfo->Type & eWORDLIST_IS_VALID )
  1920. {
  1921. //------------------------------------------
  1922. // Get tag values (vol, rate, pitch, etc.)
  1923. //------------------------------------------
  1924. GetItemControls( sentItem.Words[i].pXmlState, pWordTok );
  1925. //------------------------------------------
  1926. //
  1927. //------------------------------------------
  1928. //-------------------------------------
  1929. // Switch on token type
  1930. //-------------------------------------
  1931. switch ( sentItem.Words[i].pXmlState->eAction )
  1932. {
  1933. case SPVA_Speak:
  1934. case SPVA_SpellOut:
  1935. {
  1936. //----------------------------------
  1937. // Speak this token
  1938. //----------------------------------
  1939. pWordTok->tokLen = sentItem.Words[i].ulWordLen;
  1940. if( pWordTok->tokLen > (TOKEN_LEN_MAX -1) )
  1941. {
  1942. //-----------------------------------
  1943. // Clip to max string length
  1944. //-----------------------------------
  1945. pWordTok->tokLen = TOKEN_LEN_MAX -1;
  1946. }
  1947. //--------------------------
  1948. // Copy token string
  1949. // Append C-string delimiter
  1950. //--------------------------
  1951. memcpy( &pWordTok->tokStr[0], &sentItem.Words[i].pWordText[0],
  1952. pWordTok->tokLen * sizeof(WCHAR) );
  1953. pWordTok->tokStr[pWordTok->tokLen] = 0; //string delimiter
  1954. pWordTok->phon_Len = IPA_to_Allo( sentItem.Words[i].pWordPron,
  1955. pWordTok->phon_Str );
  1956. pWordTok->POScode = sentItem.Words[i].eWordPartOfSpeech;
  1957. pWordTok->m_posClass = GetPOSClass( pWordTok->POScode );
  1958. pWordTok->srcPosition = sentItem.ulItemSrcOffset;
  1959. pWordTok->srcLen = sentItem.ulItemSrcLen;
  1960. pWordTok->m_PitchBaseOffs = m_CurPitchOffs;
  1961. pWordTok->m_PitchRangeScale = m_CurPitchRange;
  1962. pWordTok->m_ProsodyDurScale = m_RateRatio_PROSODY;
  1963. //----------------------------------
  1964. // Advance to next token
  1965. //----------------------------------
  1966. tempPos = m_TokList.AddTail( pWordTok );
  1967. if( clusterPos == NULL )
  1968. {
  1969. //--------------------------------------
  1970. // Remember where currentitem started
  1971. //--------------------------------------
  1972. clusterPos = tempPos;
  1973. }
  1974. pWordTok = NULL; // Get a new ptr next time
  1975. tokenIndex++;
  1976. lastWasTerm = false;
  1977. lastWasSil = false;
  1978. break;
  1979. }
  1980. case SPVA_Silence:
  1981. {
  1982. (void)InsertSilenceAtTail( pWordTok, &sentItem, sentItem.Words[i].pXmlState->SilenceMSecs );
  1983. pWordTok->m_SilenceSource = SIL_XML;
  1984. pWordTok = NULL; // Get a new ptr next time
  1985. tokenIndex++;
  1986. lastWasTerm = false;
  1987. break;
  1988. }
  1989. case SPVA_Pronounce:
  1990. {
  1991. pWordTok->tokStr[0] = 0; // There's no orth for Pron types
  1992. pWordTok->tokLen = 0;
  1993. pWordTok->phon_Len = IPA_to_Allo( sentItem.Words[i].pXmlState->pPhoneIds, pWordTok->phon_Str );
  1994. pWordTok->POScode = sentItem.Words[i].eWordPartOfSpeech;
  1995. pWordTok->m_posClass = GetPOSClass( pWordTok->POScode );
  1996. pWordTok->srcPosition = sentItem.ulItemSrcOffset;
  1997. pWordTok->srcLen = sentItem.ulItemSrcLen;
  1998. pWordTok->m_PitchBaseOffs = m_CurPitchOffs;
  1999. pWordTok->m_PitchRangeScale = m_CurPitchRange;
  2000. pWordTok->m_ProsodyDurScale = m_RateRatio_PROSODY;
  2001. //----------------------------------
  2002. // Advance to next token
  2003. //----------------------------------
  2004. tempPos = m_TokList.AddTail( pWordTok );
  2005. if( clusterPos == NULL )
  2006. {
  2007. //--------------------------------------
  2008. // Remember where currentitem started
  2009. //--------------------------------------
  2010. clusterPos = tempPos;
  2011. }
  2012. pWordTok = NULL; // Get a new ptr next time
  2013. tokenIndex++;
  2014. lastWasTerm = false;
  2015. lastWasSil = false;
  2016. break;
  2017. }
  2018. case SPVA_Bookmark:
  2019. {
  2020. BOOKMARK_ITEM *pMarker;
  2021. //-------------------------------------------------
  2022. // Create bookmark list if it's not already there
  2023. //-------------------------------------------------
  2024. if( pWordTok->pBMObj == NULL )
  2025. {
  2026. pWordTok->pBMObj = new CBookmarkList;
  2027. }
  2028. if( pWordTok->pBMObj )
  2029. {
  2030. //--------------------------------------------------------
  2031. // Allocate memory for bookmark string
  2032. // (add 1 to length for string delimiter)
  2033. //--------------------------------------------------------
  2034. pWordTok->tokLen = sentItem.Words[i].ulWordLen;
  2035. pMarker = new BOOKMARK_ITEM;
  2036. if (pMarker)
  2037. {
  2038. //----------------------------------------
  2039. // We'll need the text ptr and length
  2040. // when this bookmark event gets posted
  2041. //----------------------------------------
  2042. pMarker->pBMItem = (LPARAM)sentItem.pItemSrcText;
  2043. //--- Punch NULL character into end of bookmark string for Event...
  2044. WCHAR* pTemp = (WCHAR*) sentItem.pItemSrcText + sentItem.ulItemSrcLen;
  2045. *pTemp = 0;
  2046. //-----------------------------------
  2047. // Add this bookmark to list
  2048. //-----------------------------------
  2049. pWordTok->pBMObj->m_BMList.AddTail( pMarker );
  2050. }
  2051. }
  2052. break;
  2053. }
  2054. default:
  2055. {
  2056. SPDBG_DMSG1( "Unknown SPVSTATE eAction: %d\n", sentItem.Words[i].pXmlState->eAction );
  2057. break;
  2058. }
  2059. }
  2060. }
  2061. else
  2062. {
  2063. //-----------------------------
  2064. // Maybe token is punctuation
  2065. //-----------------------------
  2066. if ( fIsPunctuation(sentItem) )
  2067. {
  2068. TUNE_TYPE bType = NULL_BOUNDARY;
  2069. switch ( sentItem.pItemInfo->Type )
  2070. {
  2071. case eCOMMA:
  2072. case eSEMICOLON:
  2073. case eCOLON:
  2074. case eHYPHEN:
  2075. if( !lastWasSil )
  2076. {
  2077. bType = PHRASE_BOUNDARY;
  2078. }
  2079. break;
  2080. case ePERIOD:
  2081. if( fLastItem )
  2082. {
  2083. bType = DECLAR_BOUNDARY;
  2084. }
  2085. else
  2086. {
  2087. defaultTune = DECLAR_BOUNDARY;
  2088. }
  2089. break;
  2090. case eQUESTION:
  2091. if( fLastItem )
  2092. {
  2093. bType = YN_QUEST_BOUNDARY;
  2094. }
  2095. else
  2096. {
  2097. defaultTune = YN_QUEST_BOUNDARY;
  2098. }
  2099. break;
  2100. case eEXCLAMATION:
  2101. if( fLastItem )
  2102. {
  2103. bType = EXCLAM_BOUNDARY;
  2104. }
  2105. else
  2106. {
  2107. defaultTune = EXCLAM_BOUNDARY;
  2108. }
  2109. break;
  2110. }
  2111. if( (bType != NULL_BOUNDARY) && (tokenIndex > 0) )
  2112. {
  2113. pWordTok->m_TuneBoundaryType = bType;
  2114. pWordTok->phon_Len = 1;
  2115. pWordTok->phon_Str[0] = _SIL_;
  2116. pWordTok->srcPosition = sentItem.ulItemSrcOffset;
  2117. pWordTok->srcLen = sentItem.ulItemSrcLen;
  2118. pWordTok->tokStr[0] = sentItem.pItemSrcText[0]; // punctuation
  2119. pWordTok->tokStr[1] = 0; // delimiter
  2120. pWordTok->tokLen = 1;
  2121. pWordTok->m_SilenceSource = SIL_Term;
  2122. pWordTok->m_TermSil = 0;
  2123. //----------------------------------
  2124. // Advance to next token
  2125. //----------------------------------
  2126. tempPos = m_TokList.AddTail( pWordTok );
  2127. if( clusterPos == NULL )
  2128. {
  2129. //--------------------------------------
  2130. // Remember where currentitem started
  2131. //--------------------------------------
  2132. clusterPos = tempPos;
  2133. }
  2134. pWordTok = NULL; // Get a new ptr next time
  2135. tokenIndex++;
  2136. lastWasTerm = true;
  2137. lastWasSil = true;
  2138. }
  2139. }
  2140. else
  2141. {
  2142. switch ( sentItem.pItemInfo->Type )
  2143. {
  2144. //case eSINGLE_QUOTE:
  2145. case eDOUBLE_QUOTE:
  2146. if( StateQuoteProsody( pWordTok, &sentItem, (!fLastItem) & (!lastWasSil) ) )
  2147. {
  2148. if( (!fLastItem) & (!lastWasSil) )
  2149. {
  2150. pWordTok = NULL; // Get a new ptr next time
  2151. tokenIndex++;
  2152. }
  2153. lastWasTerm = false;
  2154. lastWasSil = true;
  2155. }
  2156. break;
  2157. case eOPEN_PARENTHESIS:
  2158. case eOPEN_BRACKET:
  2159. case eOPEN_BRACE:
  2160. if( StartParenProsody( pWordTok, &sentItem, !fLastItem ) )
  2161. {
  2162. if( !fLastItem )
  2163. {
  2164. pWordTok = NULL; // Get a new ptr next time
  2165. tokenIndex++;
  2166. }
  2167. lastWasTerm = false;
  2168. lastWasSil = true;
  2169. }
  2170. break;
  2171. case eCLOSE_PARENTHESIS:
  2172. case eCLOSE_BRACKET:
  2173. case eCLOSE_BRACE:
  2174. if( EndParenProsody( pWordTok, &sentItem, !fLastItem ) )
  2175. {
  2176. if( !fLastItem )
  2177. {
  2178. pWordTok = NULL; // Get a new ptr next time
  2179. tokenIndex++;
  2180. }
  2181. lastWasTerm = false;
  2182. lastWasSil = true;
  2183. }
  2184. break;
  2185. }
  2186. }
  2187. }
  2188. }
  2189. else
  2190. {
  2191. eHR = E_OUTOFMEMORY;
  2192. break;
  2193. }
  2194. if( --cCurWord == 0 )
  2195. {
  2196. cCurItem++;
  2197. }
  2198. if( cCurItem == cNumOfItems )
  2199. {
  2200. fLastItem = true;
  2201. }
  2202. }
  2203. //-------------------------------------
  2204. // Tag special word clusters
  2205. //-------------------------------------
  2206. ProsodyTemplates( clusterPos, &sentItem );
  2207. }
  2208. pItemizer->Release();
  2209. //------------------------------------------------------
  2210. // Make sure sentence ends on termination
  2211. //------------------------------------------------------
  2212. if( !lastWasTerm )
  2213. {
  2214. //------------------------
  2215. // Add a comma
  2216. //------------------------
  2217. if( pWordTok == NULL )
  2218. {
  2219. pWordTok = new CFEToken;
  2220. }
  2221. if( pWordTok )
  2222. {
  2223. pWordTok->m_TuneBoundaryType = defaultTune;
  2224. pWordTok->m_BoundarySource = BND_ForcedTerm;
  2225. pWordTok->m_SilenceSource = SIL_Term;
  2226. pWordTok->phon_Len = 1;
  2227. pWordTok->phon_Str[0] = _SIL_;
  2228. pWordTok->srcPosition = sentItem.ulItemSrcOffset;
  2229. pWordTok->srcLen = sentItem.ulItemSrcLen;
  2230. pWordTok->tokStr[0] = '.'; // punctuation
  2231. pWordTok->tokStr[1] = 0; // delimiter
  2232. pWordTok->tokLen = 1;
  2233. // pWordTok->m_BoundarySource = bndSource;
  2234. //----------------------------------
  2235. // Advance to next token
  2236. //----------------------------------
  2237. tempPos = m_TokList.AddTail( pWordTok );
  2238. if( clusterPos == NULL )
  2239. {
  2240. //--------------------------------------
  2241. // Remember where current item started
  2242. //--------------------------------------
  2243. clusterPos = tempPos;
  2244. }
  2245. pWordTok = NULL; // Get a new ptr next time
  2246. tokenIndex++;
  2247. }
  2248. else
  2249. {
  2250. //----------------------------------
  2251. // Bail-out or we'll crash
  2252. //----------------------------------
  2253. eHR = E_OUTOFMEMORY;
  2254. }
  2255. }
  2256. m_cNumOfWords = tokenIndex;
  2257. if( eHR == S_FALSE )
  2258. {
  2259. //----------------------------------
  2260. // Return only errors
  2261. //----------------------------------
  2262. eHR = S_OK;
  2263. }
  2264. }
  2265. else
  2266. {
  2267. eHR = eHR; // !!!!
  2268. }
  2269. //-------------------------------
  2270. // Cleanup memory allocation
  2271. //-------------------------------
  2272. if( pWordTok != NULL )
  2273. {
  2274. delete pWordTok;
  2275. }
  2276. //---------------------------------------------------
  2277. // Get sentence position and length for SAPI events
  2278. //---------------------------------------------------
  2279. CalcSentenceLength();
  2280. return eHR;
  2281. } /* CFrontend::GetSentenceTokens */
  2282. /*****************************************************************************
  2283. * CFrontend::CalcSentenceLength *
  2284. *-------------------------------*
  2285. * Description:
  2286. * Loop thru token list and sum the source char count.
  2287. *
  2288. ********************************************************************** MC ***/
  2289. void CFrontend::CalcSentenceLength()
  2290. {
  2291. long firstIndex, lastIndex, lastLen;
  2292. bool firstState;
  2293. SPLISTPOS listPos;
  2294. CFEToken *pWordTok, *pFirstTok = NULL;
  2295. //---------------------------------------------
  2296. // Find the 1st and last words in sentence
  2297. //---------------------------------------------
  2298. firstIndex = lastIndex = lastLen = 0;
  2299. firstState = true;
  2300. listPos = m_TokList.GetHeadPosition();
  2301. while( listPos )
  2302. {
  2303. pWordTok = m_TokList.GetNext( listPos );
  2304. //-------------------------------------------
  2305. // Look at at displayable words only
  2306. //-------------------------------------------
  2307. if( pWordTok->srcLen > 0 )
  2308. {
  2309. if( firstState )
  2310. {
  2311. firstState = false;
  2312. firstIndex = pWordTok->srcPosition;
  2313. pFirstTok = pWordTok;
  2314. }
  2315. else
  2316. {
  2317. lastIndex = pWordTok->srcPosition;
  2318. lastLen = pWordTok->srcLen;
  2319. }
  2320. }
  2321. }
  2322. //--------------------------------------------------
  2323. // Calculate sentence length for head list item
  2324. //--------------------------------------------------
  2325. if( pFirstTok )
  2326. {
  2327. pFirstTok->sentencePosition = firstIndex; // Sentence starts here...
  2328. pFirstTok->sentenceLen = (lastIndex - firstIndex) + lastLen; // ...and this is the length
  2329. }
  2330. }
  2331. /*****************************************************************************
  2332. * CFrontend::DisposeUnits *
  2333. *-------------------------*
  2334. * Description:
  2335. * Delete memory allocated to 'm_pUnits'.
  2336. * Clean-up memory for Bookmarks
  2337. *
  2338. ********************************************************************** MC ***/
  2339. #ifdef USE_VOICEDATAOBJ
  2340. void CFrontend::DisposeUnits( )
  2341. {
  2342. SPDBG_FUNC( "CFrontend::DisposeUnits" );
  2343. ULONG unitIndex;
  2344. if( m_pUnits )
  2345. {
  2346. //-----------------------------------------
  2347. // Clean-up Bookmark memory allocation
  2348. //-----------------------------------------
  2349. for( unitIndex = m_CurUnitIndex; unitIndex < m_unitCount; unitIndex++)
  2350. {
  2351. if( m_pUnits[unitIndex].pBMObj != NULL )
  2352. {
  2353. //---------------------------------------
  2354. // Dispose bookmark list
  2355. //---------------------------------------
  2356. delete m_pUnits[unitIndex].pBMObj;
  2357. m_pUnits[unitIndex].pBMObj = NULL;
  2358. }
  2359. }
  2360. delete m_pUnits;
  2361. m_pUnits = NULL;
  2362. }
  2363. } /* CFrontend::DisposeUnits */
  2364. #endif
  2365. /*****************************************************************************
  2366. * CFrontend::ParseNextSentence *
  2367. *------------------------------*
  2368. * Description:
  2369. * Fill 'm_pUnits' array with next sentence.
  2370. * If there's no more input text,
  2371. * return with 'm_SpeechState' set to SPEECH_DONE +++
  2372. *
  2373. ********************************************************************** MC ***/
  2374. HRESULT CFrontend::ParseSentence( DIRECTION eDirection )
  2375. {
  2376. SPDBG_FUNC( "CFrontend::ParseNextSentence" );
  2377. HRESULT hr = S_OK;
  2378. //-----------------------------------------------------
  2379. // If there's a previous unit array, free its memory
  2380. //-----------------------------------------------------
  2381. #ifdef USE_VOICEDATAOBJ
  2382. DisposeUnits();
  2383. #endif
  2384. m_CurUnitIndex = 0;
  2385. m_unitCount = 0;
  2386. DeleteTokenList();
  2387. #ifdef USE_VOICEDATAOBJ
  2388. m_pUnits = NULL;
  2389. #endif
  2390. //-----------------------------------------------------
  2391. // If there's a previous allo array, free its memory
  2392. //-----------------------------------------------------
  2393. if( m_pAllos )
  2394. {
  2395. delete m_pAllos;
  2396. m_pAllos = NULL;
  2397. }
  2398. //-----------------------------------------------------
  2399. // Fill token array with next sentence
  2400. // Skip empty sentences.
  2401. // NOTE: includes non-speaking items
  2402. //-----------------------------------------------------
  2403. do
  2404. {
  2405. hr = GetSentenceTokens( eDirection );
  2406. } while( (hr == S_OK) && (m_cNumOfWords == 0) );
  2407. if( hr == S_OK )
  2408. {
  2409. //--------------------------------------------
  2410. // Prepare word emphasis
  2411. //--------------------------------------------
  2412. DoWordAccent();
  2413. //--------------------------------------------
  2414. // Word level prosodic lables
  2415. //--------------------------------------------
  2416. DoPhrasing();
  2417. ToBISymbols();
  2418. //--------------------------------------------
  2419. // Convert tokens to allo list
  2420. //--------------------------------------------
  2421. m_pAllos = new CAlloList;
  2422. if (m_pAllos == NULL)
  2423. {
  2424. //-----------------------
  2425. // Out of memory
  2426. //-----------------------
  2427. hr = E_FAIL;
  2428. }
  2429. if( SUCCEEDED(hr) )
  2430. {
  2431. //--------------------------------
  2432. // Convert word to allo strteam
  2433. //-------------------------------
  2434. TokensToAllo( &m_TokList, m_pAllos );
  2435. //----------------------------
  2436. // Tag sentence syllables
  2437. //----------------------------
  2438. m_SyllObj.TagSyllables( m_pAllos );
  2439. //--------------------------------------------
  2440. // Dispose token array, no longer needed
  2441. //--------------------------------------------
  2442. DeleteTokenList();
  2443. //--------------------------------------------
  2444. // Create the unit array
  2445. // NOTE:
  2446. //--------------------------------------------
  2447. #ifdef USE_VOICEDATAOBJ
  2448. hr = UnitLookahead ();
  2449. if( hr == S_OK )
  2450. {
  2451. //--------------------------------------------
  2452. // Compute allo durations
  2453. //--------------------------------------------
  2454. UnitToAlloDur( m_pAllos, m_pUnits );
  2455. m_DurObj.AlloDuration( m_pAllos, m_RateRatio_API );
  2456. //--------------------------------------------
  2457. // Modulate allo pitch
  2458. //--------------------------------------------
  2459. m_PitchObj.AlloPitch( m_pAllos, m_BasePitch, m_PitchRange );
  2460. }
  2461. #else
  2462. m_DurObj.AlloDuration( m_pAllos, m_RateRatio_API );
  2463. m_PitchObj.AlloPitch( m_pAllos, m_BasePitch, m_PitchRange );
  2464. #endif
  2465. }
  2466. #ifdef USE_VOICEDATAOBJ
  2467. if( hr == S_OK )
  2468. {
  2469. AlloToUnitPitch( m_pAllos, m_pUnits );
  2470. }
  2471. #endif
  2472. }
  2473. if( FAILED(hr) )
  2474. {
  2475. //------------------------------------------
  2476. // Either the input text is dry or we failed.
  2477. // Try to fail gracefully
  2478. // 1 - Clean up memory
  2479. // 2 - End the speech
  2480. //------------------------------------------
  2481. if( m_pAllos )
  2482. {
  2483. delete m_pAllos;
  2484. m_pAllos = 0;
  2485. }
  2486. DeleteTokenList();
  2487. #ifdef USE_VOICEDATAOBJ
  2488. DisposeUnits();
  2489. #endif
  2490. m_SpeechState = SPEECH_DONE;
  2491. }
  2492. else if( hr == S_FALSE )
  2493. {
  2494. //---------------------------------
  2495. // No more input text
  2496. //---------------------------------
  2497. hr = S_OK;
  2498. m_SpeechState = SPEECH_DONE;
  2499. }
  2500. return hr;
  2501. } /* CFrontend::ParseNextSentence */
  2502. /*****************************************************************************
  2503. * CFrontend::UnitLookahead *
  2504. *--------------------------*
  2505. * Description:
  2506. *
  2507. ********************************************************************** MC ***/
  2508. #ifdef USE_VOICEDATAOBJ
  2509. HRESULT CFrontend::UnitLookahead ()
  2510. {
  2511. SPDBG_FUNC( "CFrontend::UnitLookahead" );
  2512. HRESULT hr = S_OK;
  2513. UNIT_CVT *pPhon2Unit = NULL;
  2514. ULONG i;
  2515. m_unitCount = m_pAllos->GetCount();
  2516. m_pUnits = new UNITINFO[m_unitCount];
  2517. if( m_pUnits )
  2518. {
  2519. pPhon2Unit = new UNIT_CVT[m_unitCount];
  2520. if( pPhon2Unit )
  2521. {
  2522. //--------------------------------------------
  2523. // Convert allo list to unit array
  2524. //--------------------------------------------
  2525. memset( m_pUnits, 0, m_unitCount * sizeof(UNITINFO) );
  2526. hr = AlloToUnit( m_pAllos, m_pUnits );
  2527. if( SUCCEEDED(hr) )
  2528. {
  2529. //--------------------------------------------
  2530. // Initialize UNIT_CVT
  2531. //--------------------------------------------
  2532. for( i = 0; i < m_unitCount; i++ )
  2533. {
  2534. pPhon2Unit[i].PhonID = m_pUnits[i].PhonID;
  2535. pPhon2Unit[i].flags = m_pUnits[i].flags;
  2536. }
  2537. //--------------------------------------------
  2538. // Compute triphone IDs
  2539. //--------------------------------------------
  2540. hr = m_pVoiceDataObj->GetUnitIDs( pPhon2Unit, m_unitCount );
  2541. if( SUCCEEDED(hr) )
  2542. {
  2543. //--------------------------------------------
  2544. // Copy UNIT_CVT to UNITINFO
  2545. //--------------------------------------------
  2546. for( i = 0; i < m_unitCount; i++ )
  2547. {
  2548. m_pUnits[i].UnitID = pPhon2Unit[i].UnitID;
  2549. m_pUnits[i].SenoneID = pPhon2Unit[i].SenoneID;
  2550. m_pUnits[i].duration = pPhon2Unit[i].Dur;
  2551. m_pUnits[i].amp = pPhon2Unit[i].Amp;
  2552. m_pUnits[i].ampRatio = pPhon2Unit[i].AmpRatio;
  2553. strcpy( m_pUnits[i].szUnitName, pPhon2Unit[i].szUnitName );
  2554. }
  2555. }
  2556. else
  2557. {
  2558. //-----------------------
  2559. // Can't get unit ID's
  2560. //-----------------------
  2561. delete m_pUnits;
  2562. m_pUnits = NULL;
  2563. }
  2564. }
  2565. else
  2566. {
  2567. //-----------------------
  2568. // Can't convert allos
  2569. //-----------------------
  2570. delete m_pUnits;
  2571. m_pUnits = NULL;
  2572. }
  2573. }
  2574. else
  2575. {
  2576. //-----------------------
  2577. // Out of memory
  2578. //-----------------------
  2579. delete m_pUnits;
  2580. m_pUnits = NULL;
  2581. hr = E_FAIL;
  2582. }
  2583. }
  2584. else
  2585. {
  2586. //-----------------------
  2587. // Out of memory
  2588. //-----------------------
  2589. hr = E_FAIL;
  2590. }
  2591. //------------------------------
  2592. // Cleanup before exit
  2593. //------------------------------
  2594. if( pPhon2Unit )
  2595. {
  2596. delete pPhon2Unit;
  2597. }
  2598. return hr;
  2599. } /* CFrontend::UnitLookahead */
  2600. #endif
  2601. /*****************************************************************************
  2602. * CFrontend::UnitToAlloDur *
  2603. *--------------------------*
  2604. * Description:
  2605. *
  2606. ********************************************************************** MC ***/
  2607. void CFrontend::UnitToAlloDur( CAlloList *pAllos, UNITINFO *pu )
  2608. {
  2609. SPDBG_FUNC( "CFrontend::UnitToAlloDur" );
  2610. CAlloCell *pCurCell;
  2611. pCurCell = pAllos->GetHeadCell();
  2612. while( pCurCell )
  2613. {
  2614. pCurCell->m_UnitDur = pu->duration;
  2615. pu++;
  2616. pCurCell = pAllos->GetNextCell();
  2617. }
  2618. } /* CFrontend::UnitToAlloDur */
  2619. /*****************************************************************************
  2620. * CFrontend::AlloToUnitPitch *
  2621. *----------------------------*
  2622. * Description:
  2623. *
  2624. ********************************************************************** MC ***/
  2625. #ifdef USE_VOICEDATAOBJ
  2626. void CFrontend::AlloToUnitPitch( CAlloList *pAllos, UNITINFO *pu )
  2627. {
  2628. SPDBG_FUNC( "CFrontend::AlloToUnitPitch" );
  2629. ULONG k;
  2630. CAlloCell *pCurCell;
  2631. pCurCell = pAllos->GetHeadCell();
  2632. while( pCurCell )
  2633. {
  2634. pu->duration = pCurCell->m_ftDuration;
  2635. for( k = 0; k < pu->nKnots; k++ )
  2636. {
  2637. pu->pTime[k] = pCurCell->m_ftTime[k] * m_SampleRate;
  2638. pu->pF0[k] = pCurCell->m_ftPitch[k];
  2639. pu->pAmp[k] = pu->ampRatio;
  2640. }
  2641. pu++;
  2642. pCurCell = pAllos->GetNextCell();
  2643. }
  2644. } /* CFrontend::AlloToUnitPitch */
  2645. #endif
  2646. /*****************************************************************************
  2647. * CAlloList::DeleteTokenList *
  2648. *----------------------------*
  2649. * Description:
  2650. * Remove every item in link list.
  2651. *
  2652. ********************************************************************** MC ***/
  2653. void CFrontend::DeleteTokenList()
  2654. {
  2655. SPDBG_FUNC( "CFrontend::DeleteTokenList" );
  2656. CFEToken *pTok;
  2657. while( !m_TokList.IsEmpty() )
  2658. {
  2659. pTok = (CFEToken*)m_TokList.RemoveHead();
  2660. delete pTok;
  2661. }
  2662. } /* CFrontend::DeleteTokenList */
  2663. /*****************************************************************************
  2664. * AdjustQuestTune *
  2665. *-----------------*
  2666. * Description:
  2667. * Adjust termination for either YN or WH sentence tune.
  2668. *
  2669. ********************************************************************** MC ***/
  2670. static void AdjustQuestTune( CFEToken *pTok, bool fIsYesNo )
  2671. {
  2672. SPDBG_FUNC( "AdjustQuestTune" );
  2673. if ( pTok->m_TuneBoundaryType > NULL_BOUNDARY )
  2674. {
  2675. if( (pTok->m_TuneBoundaryType == YN_QUEST_BOUNDARY) ||
  2676. (pTok->m_TuneBoundaryType == WH_QUEST_BOUNDARY) )
  2677. {
  2678. //------------------------------------
  2679. // Is this a yes/no question phrase
  2680. //------------------------------------
  2681. if( fIsYesNo )
  2682. {
  2683. //------------------------------------------
  2684. // Put out a final yes/no question marker
  2685. //------------------------------------------
  2686. pTok->m_TuneBoundaryType = YN_QUEST_BOUNDARY;
  2687. pTok->m_BoundarySource = BND_YNQuest;
  2688. }
  2689. else
  2690. {
  2691. //------------------------------------------------------------------------
  2692. // Use declarative phrase marker (for WH questions)
  2693. //------------------------------------------------------------------------
  2694. pTok->m_TuneBoundaryType = WH_QUEST_BOUNDARY;
  2695. pTok->m_BoundarySource = BND_WHQuest;
  2696. }
  2697. }
  2698. }
  2699. } /* AdjustQuestTune */
  2700. typedef enum
  2701. {
  2702. p_Interj,
  2703. P_Adv,
  2704. P_Verb,
  2705. P_Adj,
  2706. P_Noun,
  2707. PRIORITY_SIZE,
  2708. } CONTENT_PRIORITY;
  2709. #define NO_POSITION -1
  2710. /*****************************************************************************
  2711. * CFrontend::ExclamEmph *
  2712. *-----------------------*
  2713. * Description:
  2714. * Find a likely word to emph if sentence has exclamation
  2715. *
  2716. ********************************************************************** MC ***/
  2717. void CFrontend::ExclamEmph()
  2718. {
  2719. SPDBG_FUNC( "CFrontend::ExclamEmph" );
  2720. CFEToken *pCur_Tok;
  2721. SPLISTPOS listPos, targetPos, curPos, contentPos[PRIORITY_SIZE];
  2722. long cContent, cWords;
  2723. long i;
  2724. for(i = 0; i < PRIORITY_SIZE; i++ )
  2725. {
  2726. contentPos[i] = (SPLISTPOS)NO_POSITION;
  2727. }
  2728. listPos = m_TokList.GetTailPosition();
  2729. pCur_Tok = m_TokList.GetNext( listPos );
  2730. //---------------------------------------------------
  2731. // First, check last token fors an exclamation
  2732. //---------------------------------------------------
  2733. if( pCur_Tok->m_TuneBoundaryType == EXCLAM_BOUNDARY )
  2734. {
  2735. //-----------------------------------------------------
  2736. // Then, see if there's only one content word
  2737. // in the sentence
  2738. //-----------------------------------------------------
  2739. cContent = cWords = 0;
  2740. listPos = m_TokList.GetHeadPosition();
  2741. while( listPos )
  2742. {
  2743. curPos = listPos;
  2744. pCur_Tok = m_TokList.GetNext( listPos );
  2745. if( pCur_Tok->m_posClass == POS_CONTENT )
  2746. {
  2747. cContent++;
  2748. cWords++;
  2749. if( cContent == 1)
  2750. {
  2751. targetPos = curPos;
  2752. }
  2753. //--------------------------------------------------------
  2754. // Fill the famous Azara Content Prominence Hierarchy (ACPH)
  2755. //--------------------------------------------------------
  2756. if( (pCur_Tok->POScode == MS_Noun) && (contentPos[P_Noun] == (SPLISTPOS)NO_POSITION) )
  2757. {
  2758. contentPos[P_Noun] = curPos;
  2759. }
  2760. else if( (pCur_Tok->POScode == MS_Verb) && (contentPos[P_Verb] == (SPLISTPOS)NO_POSITION) )
  2761. {
  2762. contentPos[P_Verb] = curPos;
  2763. }
  2764. else if( (pCur_Tok->POScode == MS_Adj) && (contentPos[P_Adj] == (SPLISTPOS)NO_POSITION) )
  2765. {
  2766. contentPos[P_Adj] = curPos;
  2767. }
  2768. else if( (pCur_Tok->POScode == MS_Adv) && (contentPos[P_Adv] == (SPLISTPOS)NO_POSITION) )
  2769. {
  2770. contentPos[P_Adv] = curPos;
  2771. }
  2772. else if( (pCur_Tok->POScode == MS_Interjection) && (contentPos[p_Interj] == (SPLISTPOS)NO_POSITION) )
  2773. {
  2774. contentPos[p_Interj] = curPos;
  2775. }
  2776. }
  2777. else if( pCur_Tok->m_posClass == POS_FUNC )
  2778. {
  2779. cWords++;
  2780. if( cWords == 1)
  2781. {
  2782. targetPos = curPos;
  2783. }
  2784. }
  2785. }
  2786. //--------------------------------------------
  2787. // If there's only one word or content word
  2788. // then EMPHASIZE it
  2789. //--------------------------------------------
  2790. if( (cContent == 1) || (cWords == 1) )
  2791. {
  2792. pCur_Tok = m_TokList.GetNext( targetPos );
  2793. pCur_Tok->user_Emph = 1;
  2794. }
  2795. else if( cContent > 1 )
  2796. {
  2797. for(i = 0; i < PRIORITY_SIZE; i++ )
  2798. {
  2799. if( contentPos[i] != (SPLISTPOS)NO_POSITION )
  2800. {
  2801. targetPos = contentPos[i];
  2802. break;
  2803. }
  2804. }
  2805. pCur_Tok = m_TokList.GetNext( targetPos );
  2806. pCur_Tok->user_Emph = 1;
  2807. }
  2808. }
  2809. } //ExclamEmph
  2810. /*****************************************************************************
  2811. * CFrontend::DoWordAccent *
  2812. *-------------------------*
  2813. * Description:
  2814. * Prepare word for emphasis
  2815. *
  2816. ********************************************************************** MC ***/
  2817. void CFrontend::DoWordAccent()
  2818. {
  2819. SPDBG_FUNC( "CFrontend::DoWordAccent" );
  2820. long cNumOfWords;
  2821. long iCurWord;
  2822. CFEToken *pCur_Tok, *pNext_Tok, *pPrev_Tok, *pTempTok;
  2823. SPLISTPOS listPos;
  2824. TUNE_TYPE cur_Bnd, prev_Bnd;
  2825. //-----------------------------
  2826. // Initilize locals
  2827. //-----------------------------
  2828. cNumOfWords = m_TokList.GetCount();
  2829. if( cNumOfWords > 0 )
  2830. {
  2831. ExclamEmph();
  2832. prev_Bnd = PHRASE_BOUNDARY; // Assume start of sentence
  2833. //-------------------------------------
  2834. // Fill the token pipeline
  2835. //-------------------------------------
  2836. listPos = m_TokList.GetHeadPosition();
  2837. //-- Previous
  2838. pPrev_Tok = NULL;
  2839. //-- Current
  2840. pCur_Tok = m_TokList.GetNext( listPos );
  2841. //-- Next
  2842. if( listPos )
  2843. {
  2844. pNext_Tok = m_TokList.GetNext( listPos );
  2845. }
  2846. else
  2847. {
  2848. pNext_Tok = NULL;
  2849. }
  2850. //-----------------------------------
  2851. // Step through entire word array
  2852. // (skip last)
  2853. //-----------------------------------
  2854. for( iCurWord = 0; iCurWord < (cNumOfWords -1); iCurWord++ )
  2855. {
  2856. cur_Bnd = pCur_Tok->m_TuneBoundaryType;
  2857. if( pCur_Tok->user_Emph > 0 )
  2858. {
  2859. //-----------------------------------
  2860. // Current word is emphasized
  2861. //-----------------------------------
  2862. if( prev_Bnd == NULL_BOUNDARY )
  2863. {
  2864. pTempTok = new CFEToken;
  2865. if( pTempTok )
  2866. {
  2867. pTempTok->user_Break = EMPH_HESITATION;
  2868. pTempTok->m_TuneBoundaryType = NULL_BOUNDARY;
  2869. pTempTok->phon_Len = 1;
  2870. pTempTok->phon_Str[0] = _SIL_;
  2871. pTempTok->srcPosition = pCur_Tok->srcPosition;
  2872. pTempTok->srcLen = pCur_Tok->srcLen;
  2873. pTempTok->tokStr[0] = 0; // There's no orth for Break
  2874. pTempTok->tokLen = 0;
  2875. pTempTok->m_TermSil = 0;
  2876. pTempTok->m_SilenceSource = SIL_Emph;
  2877. pTempTok->m_DurScale = 0;
  2878. if( pPrev_Tok )
  2879. {
  2880. //pTempTok->m_DurScale = pPrev_Tok->m_DurScale;
  2881. pTempTok->m_ProsodyDurScale = pPrev_Tok->m_ProsodyDurScale;
  2882. pTempTok->user_Volume = pPrev_Tok->user_Volume;
  2883. }
  2884. else
  2885. {
  2886. //pTempTok->m_DurScale = 1.0f;
  2887. pTempTok->m_ProsodyDurScale = 1.0f;
  2888. }
  2889. m_TokList.InsertBefore( m_TokList.FindIndex( iCurWord ), pTempTok );
  2890. pCur_Tok = pTempTok;
  2891. m_cNumOfWords++;
  2892. cNumOfWords++;
  2893. iCurWord++;
  2894. }
  2895. }
  2896. }
  2897. //------------------------------
  2898. // Shift the token pipeline
  2899. //------------------------------
  2900. prev_Bnd = cur_Bnd;
  2901. pPrev_Tok = pCur_Tok;
  2902. pCur_Tok = pNext_Tok;
  2903. if( listPos )
  2904. {
  2905. pNext_Tok = m_TokList.GetNext( listPos );
  2906. }
  2907. else
  2908. {
  2909. pNext_Tok = NULL;
  2910. }
  2911. }
  2912. }
  2913. } /* CFrontend::DoWordAccent */
  2914. /*****************************************************************************
  2915. * CFrontend::DoPhrasing *
  2916. *-----------------------*
  2917. * Description:
  2918. * Insert sub-phrase boundaries into word token array
  2919. *
  2920. ********************************************************************** MC ***/
  2921. void CFrontend::DoPhrasing()
  2922. {
  2923. SPDBG_FUNC( "CFrontend::DoPhrasing" );
  2924. long iCurWord;
  2925. CFEToken *pCur_Tok, *pNext_Tok, *pNext2_Tok, *pNext3_Tok, *pTempTok, *pPrev_Tok;
  2926. ENGPARTOFSPEECH cur_POS, next_POS, next2_POS, next3_POS, prev_POS;
  2927. bool fNext_IsPunct, fNext2_IsPunct, fNext3_IsPunct;
  2928. bool fIsYesNo, fMaybeWH, fHasDet, fInitial_Adv, fIsShortSent, fIsAlphaWH;
  2929. TUNE_TYPE cur_Bnd, prev_Punct;
  2930. long punctDistance;
  2931. long cNumOfWords;
  2932. SPLISTPOS listPos;
  2933. BOUNDARY_SOURCE bndNum;
  2934. ACCENT_SOURCE accNum;
  2935. //-----------------------------
  2936. // Initialize locals
  2937. //-----------------------------
  2938. cNumOfWords = m_TokList.GetCount();
  2939. if( cNumOfWords > 0 )
  2940. {
  2941. cur_Bnd = NULL_BOUNDARY;
  2942. prev_POS = MS_Unknown;
  2943. prev_Punct = PHRASE_BOUNDARY; // Assume start of sentence
  2944. punctDistance = 0; // To quiet the compiler...
  2945. fIsYesNo = fMaybeWH = fHasDet = fIsAlphaWH = false; // To quiet the compiler...
  2946. fMaybeWH = false;
  2947. fInitial_Adv = false;
  2948. if (cNumOfWords <= 9)
  2949. {
  2950. fIsShortSent = true;
  2951. }
  2952. else
  2953. {
  2954. fIsShortSent = false;
  2955. }
  2956. //-------------------------------------
  2957. // Fill the token pipeline
  2958. //-------------------------------------
  2959. listPos = m_TokList.GetHeadPosition();
  2960. //-- Previous
  2961. pPrev_Tok = NULL;
  2962. //-- Current
  2963. pCur_Tok = m_TokList.GetNext( listPos );
  2964. //-- Next
  2965. if( listPos )
  2966. {
  2967. pNext_Tok = m_TokList.GetNext( listPos );
  2968. }
  2969. else
  2970. {
  2971. pNext_Tok = NULL;
  2972. }
  2973. //-- Next 2
  2974. if( listPos )
  2975. {
  2976. pNext2_Tok = m_TokList.GetNext( listPos );
  2977. }
  2978. else
  2979. {
  2980. pNext2_Tok = NULL;
  2981. }
  2982. //-- Next 3
  2983. if( listPos )
  2984. {
  2985. pNext3_Tok = m_TokList.GetNext( listPos );
  2986. }
  2987. else
  2988. {
  2989. pNext3_Tok = NULL;
  2990. }
  2991. //-----------------------------------
  2992. // Step through entire word array
  2993. // (skip last)
  2994. //-----------------------------------
  2995. for( iCurWord = 0; iCurWord < (cNumOfWords -1); iCurWord++ )
  2996. {
  2997. bndNum = BND_NoSource;
  2998. accNum = ACC_NoSource;
  2999. if( (prev_Punct > NULL_BOUNDARY) && (prev_Punct < SUB_BOUNDARY_1) )
  3000. {
  3001. punctDistance = 1;
  3002. fIsYesNo = true;
  3003. fMaybeWH = false;
  3004. fHasDet = false;
  3005. fIsAlphaWH = false;
  3006. }
  3007. else
  3008. {
  3009. punctDistance++;
  3010. }
  3011. //------------------------------------
  3012. // Process new word
  3013. //------------------------------------
  3014. cur_POS = pCur_Tok->POScode;
  3015. cur_Bnd = NULL_BOUNDARY;
  3016. //------------------------------------
  3017. // Don't depend on POS to detect
  3018. // "WH" question
  3019. //------------------------------------
  3020. if( ((pCur_Tok->tokStr[0] == 'W') || (pCur_Tok->tokStr[0] == 'w')) &&
  3021. ((pCur_Tok->tokStr[1] == 'H') || (pCur_Tok->tokStr[1] == 'h')) )
  3022. {
  3023. fIsAlphaWH = true;
  3024. }
  3025. else
  3026. {
  3027. fIsAlphaWH = false;
  3028. }
  3029. //------------------------------------
  3030. // Look ahead to NEXT word
  3031. //------------------------------------
  3032. next_POS = pNext_Tok->POScode;
  3033. if( pNext_Tok->m_TuneBoundaryType != NULL_BOUNDARY )
  3034. {
  3035. fNext_IsPunct = true;
  3036. }
  3037. else
  3038. {
  3039. fNext_IsPunct = false;
  3040. }
  3041. //------------------------------------
  3042. // Look ahead 2 positions
  3043. //------------------------------------
  3044. if( pNext2_Tok )
  3045. {
  3046. next2_POS = pNext2_Tok->POScode;
  3047. if( pNext2_Tok->m_TuneBoundaryType != NULL_BOUNDARY )
  3048. {
  3049. fNext2_IsPunct = true;
  3050. }
  3051. else
  3052. {
  3053. fNext2_IsPunct = false;
  3054. }
  3055. }
  3056. else
  3057. {
  3058. next2_POS = MS_Unknown;
  3059. fNext2_IsPunct = false;
  3060. }
  3061. //------------------------------------
  3062. // Look ahead 3 positions
  3063. //------------------------------------
  3064. if( pNext3_Tok )
  3065. {
  3066. next3_POS = pNext3_Tok->POScode;
  3067. if( pNext3_Tok->m_TuneBoundaryType != NULL_BOUNDARY )
  3068. {
  3069. fNext3_IsPunct = true;
  3070. }
  3071. else
  3072. {
  3073. fNext3_IsPunct = false;
  3074. }
  3075. }
  3076. else
  3077. {
  3078. next3_POS = MS_Unknown;
  3079. fNext3_IsPunct = false;
  3080. }
  3081. //------------------------------------------------------------------------
  3082. // Is phrase a yes/no question?
  3083. //------------------------------------------------------------------------
  3084. if( punctDistance == 1 )
  3085. {
  3086. if( (cur_POS == MS_Interr) || (fIsAlphaWH) )
  3087. {
  3088. //---------------------------------
  3089. // It's a "WH" question
  3090. //---------------------------------
  3091. fIsYesNo = false;
  3092. }
  3093. else if( (cur_POS == MS_Prep) || (cur_POS == MS_Conj) || (cur_POS == MS_CConj) )
  3094. {
  3095. fMaybeWH = true;
  3096. }
  3097. }
  3098. else if( (punctDistance == 2) && (fMaybeWH) &&
  3099. ((cur_POS == MS_Interr) || (cur_POS == MS_RelPron) || (fIsAlphaWH)) )
  3100. {
  3101. fIsYesNo = false;
  3102. }
  3103. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3104. // SUB_BOUNDARY_1: Insert boundary after sentence-initial adverb
  3105. //
  3106. // Reluctantly __the cat sat on the mat.
  3107. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3108. if( fInitial_Adv )
  3109. {
  3110. cur_Bnd = SUB_BOUNDARY_1;
  3111. fInitial_Adv = false;
  3112. bndNum = BND_PhraseRule1;
  3113. accNum = ACC_PhraseRule1;
  3114. }
  3115. else
  3116. {
  3117. if( (punctDistance == 1) &&
  3118. (cur_POS == MS_Adv) && (next_POS == MS_Det) )
  3119. // include
  3120. //LEX_SUBJPRON // he
  3121. //LEX_DPRON // this
  3122. //LEX_IPRON // everybody
  3123. //NOT LEX_PPRON // myself
  3124. {
  3125. fInitial_Adv = true;
  3126. }
  3127. else
  3128. {
  3129. fInitial_Adv = false;
  3130. }
  3131. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3132. // SUB_BOUNDARY_2:Insert boundary before coordinating conjunctions
  3133. // The cat sat on the mat __and cleaned his fur.
  3134. //
  3135. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3136. if( (cur_POS == MS_CConj) &&
  3137. (fHasDet == false) &&
  3138. (punctDistance > 3) &&
  3139. (next2_POS != MS_Conj) )
  3140. {
  3141. cur_Bnd = SUB_BOUNDARY_2;
  3142. bndNum = BND_PhraseRule2;
  3143. accNum = ACC_PhraseRule2;
  3144. }
  3145. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3146. // SUB_BOUNDARY_2:Insert boundary before adverb
  3147. // The cat sat on the mat __reluctantly.
  3148. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3149. else if( (cur_POS == MS_Adv) &&
  3150. (punctDistance > 4) &&
  3151. (next_POS != MS_Adj) )
  3152. {
  3153. cur_Bnd = SUB_BOUNDARY_2;
  3154. bndNum = BND_PhraseRule3;
  3155. accNum = ACC_PhraseRule3;
  3156. }
  3157. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3158. // SUB_BOUNDARY_2:Insert boundary after object pronoun
  3159. // The cat sat with me__ on the mat.
  3160. //
  3161. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3162. else if( (prev_POS == MS_ObjPron) && (punctDistance > 2))
  3163. {
  3164. cur_Bnd = SUB_BOUNDARY_2;
  3165. bndNum = BND_PhraseRule4;
  3166. accNum = ACC_PhraseRule4;
  3167. }
  3168. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3169. // SUB_BOUNDARY_2:Insert boundary before subject pronoun or contraction
  3170. // The cat sat on the mat _I see.
  3171. // The cat sat on the mat _I'm sure.
  3172. //
  3173. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3174. else if( ((cur_POS == MS_SubjPron) || (cur_POS == MS_Contr) ) &&
  3175. (punctDistance > 3) && (prev_POS != MS_RelPron) && (prev_POS != MS_Conj))
  3176. {
  3177. cur_Bnd = SUB_BOUNDARY_2;
  3178. bndNum = BND_PhraseRule5;
  3179. accNum = ACC_PhraseRule5;
  3180. }
  3181. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3182. // SUB_BOUNDARY_2:Insert boundary before interr
  3183. // The cat sat on the mat _how odd.
  3184. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3185. else if( (cur_POS == MS_Interr) && (punctDistance > 4) )
  3186. {
  3187. cur_Bnd = SUB_BOUNDARY_2;
  3188. bndNum = BND_PhraseRule6;
  3189. accNum = ACC_PhraseRule6;
  3190. }
  3191. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3192. // SUB_BOUNDARY_3:Insert boundary after subject noun phrase followed by aux verb
  3193. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3194. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3195. // SUB_BOUNDARY_3:Insert boundary before vaux after noun phrase
  3196. // The gray cat __should sit on the mat.
  3197. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3198. else if( (punctDistance > 2) &&
  3199. ( ((prev_POS == MS_Noun) || (prev_POS == MS_Verb)) && (prev_POS != MS_VAux) ) &&
  3200. (cur_POS == MS_VAux)
  3201. )
  3202. {
  3203. cur_Bnd = SUB_BOUNDARY_3;
  3204. bndNum = BND_PhraseRule7;
  3205. accNum = ACC_PhraseRule7;
  3206. }
  3207. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3208. // SUB_BOUNDARY_3:Insert boundary after MS_Interr
  3209. // The gray cat __should sit on the mat.
  3210. // SEE ABOVE???
  3211. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3212. /*else if( (prev_POS == MS_Noun) && ((next_POS != MS_RelPron) &&
  3213. (next_POS != MS_VAux) && (next_POS != MS_RVAux) &&
  3214. (next2_POS != MS_VAux) && (next2_POS != MS_RVAux)) &&
  3215. (punctDistance > 4) &&
  3216. ((cur_POS == MS_VAux) || (cur_POS == MS_RVAux)))
  3217. {
  3218. cur_Bnd = SUB_BOUNDARY_3;
  3219. bndNum = BND_PhraseRule8;
  3220. accNum = ACC_PhraseRule8;
  3221. }*/
  3222. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3223. // SUB_BOUNDARY_3:Insert boundary after MS_Interr
  3224. // The cat sat on the mat _how odd.
  3225. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3226. else if( (prev_POS == MS_Noun) && (next_POS != MS_RelPron) &&
  3227. (next_POS != MS_Conj) &&
  3228. (next_POS != MS_CConj) && (punctDistance > 3) && (cur_POS == MS_Verb))
  3229. {
  3230. cur_Bnd = SUB_BOUNDARY_3;
  3231. bndNum = BND_PhraseRule9;
  3232. accNum = ACC_PhraseRule9;
  3233. }
  3234. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3235. // SUB_BOUNDARY_3:Insert boundary after MS_Interr
  3236. // The cat sat on the mat _how odd.
  3237. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3238. /*else if( (prev_POS == MS_Noun) && (cur_POS != MS_RelPron) &&
  3239. (cur_POS != MS_RVAux) && (cur_POS != MS_CConj) &&
  3240. (cur_POS != MS_Conj) && (punctDistance > 2) &&
  3241. ((punctDistance > 2) || (fIsShortSent)) && (cur_POS == MS_Verb))
  3242. {
  3243. cur_Bnd = SUB_BOUNDARY_3;
  3244. bndNum = BND_PhraseRule10;
  3245. accNum = ACC_PhraseRule10;
  3246. }
  3247. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3248. // SUB_BOUNDARY_4:Insert boundary before conjunction
  3249. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3250. else if( ((cur_POS == MS_Conj) && (punctDistance > 3) &&
  3251. (fNext_IsPunct == false) &&
  3252. (prev_POS != MS_Conj) && (prev_POS != MS_CConj) &&
  3253. (fNext2_IsPunct == false)) ||
  3254. ( (prev_POS == MS_VPart) && (cur_POS != MS_Prep) &&
  3255. (cur_POS != MS_Det) &&
  3256. (punctDistance > 2) &&
  3257. ((cur_POS == MS_Noun) || (cur_POS == MS_Noun) || (cur_POS == MS_Adj))) ||
  3258. ( (cur_POS == MS_Interr) && (punctDistance > 2) &&
  3259. (cur_POS == MS_SubjPron)) )
  3260. {
  3261. cur_Bnd = SUB_BOUNDARY_4;
  3262. bndNum = BND_PhraseRule11;
  3263. accNum = ACC_PhraseRule11;
  3264. }
  3265. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3266. // SUB_BOUNDARY_5:Insert boundary before relative pronoun
  3267. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3268. else if( ( (cur_POS == MS_RelPron) && (punctDistance >= 3) &&
  3269. (prev_POS != MS_Prep) && (next3_POS != MS_VAux) &&
  3270. (next3_POS != MS_RVAux) &&
  3271. ( (prev_POS == MS_Noun) || (prev_POS == MS_Verb) ) ) ||
  3272. ( (cur_POS == MS_Quant) && (punctDistance > 5) &&
  3273. (prev_POS != MS_Adj) && (prev_POS != MS_Det) &&
  3274. (prev_POS != MS_VAux) && (prev_POS != MS_RVAux) &&
  3275. (prev_POS != MS_Det) && (next2_POS != MS_CConj) &&
  3276. (fNext_IsPunct == false)))
  3277. {
  3278. cur_Bnd = SUB_BOUNDARY_5;
  3279. bndNum = BND_PhraseRule12;
  3280. accNum = ACC_PhraseRule12;
  3281. }*/
  3282. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3283. // SUB_BOUNDARY_6:Silverman87-style, content/function tone group boundaries.
  3284. // Does trivial sentence-final function word look-ahead check.
  3285. //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  3286. else if( ( (prev_POS == MS_Noun) || (prev_POS == MS_Verb) || (prev_POS == MS_Adj) || (prev_POS == MS_Adv))
  3287. && ((cur_POS != MS_Noun) && (cur_POS != MS_Verb) && (cur_POS != MS_Adj) && (cur_POS != MS_Adv))
  3288. && (fNext_IsPunct == false))
  3289. {
  3290. cur_Bnd = SUB_BOUNDARY_6;
  3291. bndNum = BND_PhraseRule13;
  3292. accNum = ACC_PhraseRule13;
  3293. }
  3294. }
  3295. //------------------------------------------------------------------------
  3296. // If phrasing was found, save it
  3297. //------------------------------------------------------------------------
  3298. if( (cur_Bnd != NULL_BOUNDARY) && (iCurWord > 0) &&
  3299. //!(fNext_IsPunct) &&
  3300. !(prev_Punct) &&
  3301. (pCur_Tok->m_TuneBoundaryType == NULL_BOUNDARY) )
  3302. {
  3303. //pCur_Tok->m_TuneBoundaryType = cur_Bnd;
  3304. pTempTok = new CFEToken;
  3305. if( pTempTok )
  3306. {
  3307. pTempTok->m_TuneBoundaryType = cur_Bnd;
  3308. pTempTok->phon_Len = 1;
  3309. pTempTok->phon_Str[0] = _SIL_;
  3310. pTempTok->srcPosition = pCur_Tok->srcPosition;
  3311. pTempTok->srcLen = pCur_Tok->srcLen;
  3312. pTempTok->tokStr[0] = '+'; // punctuation
  3313. pTempTok->tokStr[1] = 0; // delimiter
  3314. pTempTok->tokLen = 1;
  3315. pTempTok->m_TermSil = 0;
  3316. pTempTok->m_DurScale = 0;
  3317. if( pPrev_Tok )
  3318. {
  3319. pPrev_Tok->m_AccentSource = accNum;
  3320. pPrev_Tok->m_BoundarySource = bndNum;
  3321. pPrev_Tok->m_Accent = K_LHSTAR;
  3322. }
  3323. pTempTok->m_SilenceSource = SIL_SubBound;
  3324. if( pPrev_Tok )
  3325. {
  3326. //pTempTok->m_DurScale = pPrev_Tok->m_DurScale;
  3327. pTempTok->m_ProsodyDurScale = pPrev_Tok->m_ProsodyDurScale;
  3328. pTempTok->user_Volume = pPrev_Tok->user_Volume;
  3329. }
  3330. else
  3331. {
  3332. //pTempTok->m_DurScale = 1.0f;
  3333. pTempTok->m_ProsodyDurScale = 1.0f;
  3334. }
  3335. m_TokList.InsertBefore( m_TokList.FindIndex( iCurWord ), pTempTok );
  3336. pCur_Tok = pTempTok;
  3337. m_cNumOfWords++;
  3338. cNumOfWords++;
  3339. iCurWord++;
  3340. }
  3341. }
  3342. //-------------------------------
  3343. // Process sentence punctuation
  3344. //-------------------------------
  3345. AdjustQuestTune( pCur_Tok, fIsYesNo );
  3346. //-------------------------------
  3347. // Prepare for next word
  3348. //-------------------------------
  3349. prev_Punct = pCur_Tok->m_TuneBoundaryType;
  3350. prev_POS = cur_POS;
  3351. pPrev_Tok = pCur_Tok;
  3352. //------------------------------
  3353. // Shift the token pipeline
  3354. //------------------------------
  3355. pCur_Tok = pNext_Tok;
  3356. pNext_Tok = pNext2_Tok;
  3357. pNext2_Tok = pNext3_Tok;
  3358. if( listPos )
  3359. {
  3360. pNext3_Tok = m_TokList.GetNext( listPos );
  3361. }
  3362. else
  3363. {
  3364. pNext3_Tok = NULL;
  3365. }
  3366. //------------------------------------------------------------------------
  3367. // Keep track of when determiners encountered to help in deciding
  3368. // when to allow a strong 'and' boundary (SUB_BOUNDARY_2)
  3369. //------------------------------------------------------------------------
  3370. if( punctDistance > 2)
  3371. {
  3372. fHasDet = false;
  3373. }
  3374. if( cur_POS == MS_Det )
  3375. {
  3376. fHasDet = true;
  3377. }
  3378. }
  3379. //-------------------------------------
  3380. // Process final sentence punctuation
  3381. //-------------------------------------
  3382. pCur_Tok = (CFEToken*)m_TokList.GetTail();
  3383. AdjustQuestTune( pCur_Tok, fIsYesNo );
  3384. }
  3385. } /* CFrontend::DoPhrasing */
  3386. /*****************************************************************************
  3387. * CFrontend::RecalcProsody *
  3388. *--------------------------*
  3389. * Description:
  3390. * In response to a real-time rate change, recalculate duration and pitch
  3391. *
  3392. ********************************************************************** MC ***/
  3393. #ifdef USE_VOICEDATAOBJ
  3394. void CFrontend::RecalcProsody()
  3395. {
  3396. SPDBG_FUNC( "CFrontend::RecalcProsody" );
  3397. UNITINFO* pu;
  3398. CAlloCell* pCurCell;
  3399. ULONG k;
  3400. //--------------------------------------------
  3401. // Compute new allo durations
  3402. //--------------------------------------------
  3403. /*pCurCell = m_pAllos->GetHeadCell();
  3404. while( pCurCell )
  3405. {
  3406. //pCurCell->m_DurScale = 1.0;
  3407. pCurCell = m_pAllos->GetNextCell();
  3408. }*/
  3409. m_DurObj.AlloDuration( m_pAllos, m_RateRatio_API );
  3410. //--------------------------------------------
  3411. // Modulate allo pitch
  3412. //--------------------------------------------
  3413. m_PitchObj.AlloPitch( m_pAllos, m_BasePitch, m_PitchRange );
  3414. pu = m_pUnits;
  3415. pCurCell = m_pAllos->GetHeadCell();
  3416. while( pCurCell )
  3417. {
  3418. pu->duration = pCurCell->m_ftDuration;
  3419. for( k = 0; k < pu->nKnots; k++ )
  3420. {
  3421. pu->pTime[k] = pCurCell->m_ftTime[k] * m_SampleRate;
  3422. pu->pF0[k] = pCurCell->m_ftPitch[k];
  3423. pu->pAmp[k] = pu->ampRatio;
  3424. }
  3425. pu++;
  3426. pCurCell = m_pAllos->GetNextCell();
  3427. }
  3428. } /* CFrontend::RecalcProsody */
  3429. #endif
  3430. /*****************************************************************************
  3431. * CFrontend::NextData *
  3432. *---------------------*
  3433. * Description:
  3434. * This gets called from the backend when UNIT stream is dry.
  3435. * Parse TOKENS to ALLOS to UNITS
  3436. *
  3437. ********************************************************************** MC ***/
  3438. HRESULT CFrontend::NextData( void **pData, SPEECH_STATE *pSpeechState )
  3439. {
  3440. SPDBG_FUNC( "CFrontend::NextData" );
  3441. bool haveNewRate = false;
  3442. HRESULT hr = S_OK;
  3443. //-----------------------------------
  3444. // First, check and see if SAPI has an action
  3445. //-----------------------------------
  3446. // Check for rate change
  3447. long baseRateRatio;
  3448. if( m_pOutputSite->GetActions() & SPVES_RATE )
  3449. {
  3450. hr = m_pOutputSite->GetRate( &baseRateRatio );
  3451. if ( SUCCEEDED( hr ) )
  3452. {
  3453. if( baseRateRatio > SPMAX_VOLUME )
  3454. {
  3455. //--- Clip rate to engine maximum
  3456. baseRateRatio = MAX_USER_RATE;
  3457. }
  3458. else if ( baseRateRatio < MIN_USER_RATE )
  3459. {
  3460. //--- Clip rate to engine minimum
  3461. baseRateRatio = MIN_USER_RATE;
  3462. }
  3463. m_RateRatio_API = CntrlToRatio( baseRateRatio );
  3464. haveNewRate = true;
  3465. }
  3466. }
  3467. //---------------------------------------------
  3468. // Async stop?
  3469. //---------------------------------------------
  3470. if( SUCCEEDED( hr ) && ( m_pOutputSite->GetActions() & SPVES_ABORT ) )
  3471. {
  3472. m_SpeechState = SPEECH_DONE;
  3473. }
  3474. //---------------------------------------------
  3475. // Async skip?
  3476. //---------------------------------------------
  3477. if( SUCCEEDED( hr ) && ( m_pOutputSite->GetActions() & SPVES_SKIP ) )
  3478. {
  3479. SPVSKIPTYPE SkipType;
  3480. long SkipCount = 0;
  3481. hr = m_pOutputSite->GetSkipInfo( &SkipType, &SkipCount );
  3482. if ( SUCCEEDED( hr ) && SkipType == SPVST_SENTENCE )
  3483. {
  3484. IEnumSENTITEM *pGarbage;
  3485. //--- Skip Forwards
  3486. if ( SkipCount > 0 )
  3487. {
  3488. long OriginalSkipCount = SkipCount;
  3489. while ( SkipCount > 1 &&
  3490. ( hr = m_pEnumSent->Next( &pGarbage ) ) == S_OK )
  3491. {
  3492. SkipCount--;
  3493. pGarbage->Release();
  3494. }
  3495. if ( hr == S_OK )
  3496. {
  3497. hr = ParseSentence( eNEXT );
  3498. if ( SUCCEEDED( hr ) )
  3499. {
  3500. SkipCount--;
  3501. }
  3502. }
  3503. else if ( hr == S_FALSE )
  3504. {
  3505. m_SpeechState = SPEECH_DONE;
  3506. }
  3507. SkipCount = OriginalSkipCount - SkipCount;
  3508. }
  3509. //--- Skip Backwards
  3510. else if ( SkipCount < 0 )
  3511. {
  3512. long OriginalSkipCount = SkipCount;
  3513. while ( SkipCount < -1 &&
  3514. ( hr = m_pEnumSent->Previous( &pGarbage ) ) == S_OK )
  3515. {
  3516. SkipCount++;
  3517. pGarbage->Release();
  3518. }
  3519. if ( hr == S_OK )
  3520. {
  3521. hr = ParseSentence( ePREVIOUS );
  3522. // This case is different from the forward skip, needs to test that
  3523. // Parse sentence found something to parse!
  3524. if ( SUCCEEDED( hr ) && m_SpeechState != SPEECH_DONE)
  3525. {
  3526. SkipCount++;
  3527. }
  3528. }
  3529. else if ( hr == S_FALSE )
  3530. {
  3531. m_SpeechState = SPEECH_DONE;
  3532. }
  3533. SkipCount = OriginalSkipCount - SkipCount;
  3534. }
  3535. //--- Skip to beginning of this sentence
  3536. else
  3537. {
  3538. m_CurUnitIndex = 0;
  3539. }
  3540. hr = m_pOutputSite->CompleteSkip( SkipCount );
  3541. }
  3542. }
  3543. //---------------------------------------------
  3544. // Make sure we're still speaking
  3545. //---------------------------------------------
  3546. if( SUCCEEDED( hr ) && m_SpeechState != SPEECH_DONE )
  3547. {
  3548. /*****
  3549. if( m_CurUnitIndex >= m_unitCount)
  3550. {
  3551. //-----------------------------------
  3552. // Get next sentence from Normalizer
  3553. //-----------------------------------
  3554. hr = ParseSentence( eNEXT );
  3555. //m_SpeechState = SPEECH_DONE;
  3556. }
  3557. else if( haveNewRate )
  3558. {
  3559. //-----------------------------------
  3560. // Recalculate prosody to new rate
  3561. //-----------------------------------
  3562. RecalcProsody();
  3563. }
  3564. if( SUCCEEDED(hr) )
  3565. {
  3566. if( m_SpeechState != SPEECH_DONE )
  3567. {
  3568. //-----------------------------------
  3569. // Get next phon
  3570. //-----------------------------------
  3571. m_pUnits[m_CurUnitIndex].hasSpeech = m_HasSpeech;
  3572. *pData =( void*)&m_pUnits[m_CurUnitIndex];
  3573. m_CurUnitIndex++;
  3574. }
  3575. }
  3576. *****/
  3577. hr = ParseSentence( eNEXT );
  3578. if ( SUCCEEDED( hr ) && m_SpeechState == SPEECH_CONTINUE )
  3579. {
  3580. SentenceData *pSentData = new SentenceData;
  3581. pSentData->pPhones = new Phone[ m_pAllos->GetCount() ];
  3582. ZeroMemory( pSentData->pPhones, m_pAllos->GetCount() * sizeof( Phone ) );
  3583. pSentData->ulNumPhones = m_pAllos->GetCount();
  3584. m_PitchObj.GetContour( &pSentData->pf0, &pSentData->ulNumf0 );
  3585. float RunTime = 0.0;
  3586. float InitialSil = 0.0;
  3587. bool fInitialSil = true;
  3588. char ph[512];
  3589. typedef const char *(*MapPhoneSetFunc) (ALLO_CODE);
  3590. MapPhoneSetFunc MapPhoneSet;
  3591. if (m_fNewPhoneSet)
  3592. {
  3593. MapPhoneSet = NewMapPhoneSet;
  3594. }
  3595. else
  3596. {
  3597. MapPhoneSet = OldMapPhoneSet;
  3598. }
  3599. for ( int i = 0; i < m_pAllos->GetCount(); i++ )
  3600. {
  3601. CAlloCell *pCurCell = m_pAllos->GetCell( i );
  3602. strcpy ( ph, MapPhoneSet( pCurCell->m_allo ) );
  3603. //--- adding stress info for vowels
  3604. // if ( ( pCurCell->m_ctrlFlags & PRIMARY_STRESS ) && IsVowel ( ph ) )
  3605. // {
  3606. // strcat( ph, "s");
  3607. // }
  3608. strcpy( pSentData->pPhones[i].phone, ph );
  3609. //--- Skip initial SIL
  3610. if ( fInitialSil &&
  3611. stricmp( pSentData->pPhones[i].phone, "sil" ) == 0 )
  3612. {
  3613. InitialSil += pCurCell->m_ftDuration;
  3614. pSentData->pPhones[i].f0 = 0;
  3615. pSentData->pPhones[i].end = InitialSil;
  3616. continue;
  3617. }
  3618. //--- Skip final SIL
  3619. else if ( i == m_pAllos->GetCount() - 1 &&
  3620. stricmp( pSentData->pPhones[i].phone, "sil" ) == 0 )
  3621. {
  3622. pSentData->pPhones[i].end = RunTime + InitialSil;
  3623. break;
  3624. }
  3625. else
  3626. {
  3627. fInitialSil = false;
  3628. pSentData->pPhones[i].f0 =
  3629. GetPhoneF0( pSentData->pf0, RunTime, pCurCell->m_ftDuration );
  3630. RunTime += pCurCell->m_ftDuration;
  3631. pSentData->pPhones[i].end = RunTime + InitialSil;
  3632. }
  3633. }
  3634. *pData = (void*) pSentData;
  3635. }
  3636. }
  3637. //-------------------------------------------
  3638. // Let client know if text input is dry
  3639. //-------------------------------------------
  3640. *pSpeechState = m_SpeechState;
  3641. return hr;
  3642. } /* CFrontend::NextData */
  3643. /*****************************************************************************
  3644. * IsVowel *
  3645. *----------*
  3646. *
  3647. *********************************************************************** WD ***/
  3648. bool IsVowel ( char* ph )
  3649. {
  3650. if ( ph )
  3651. {
  3652. if ( ph[0] == 'a' || ph[0] == 'e' || ph[0] == 'i' || ph[0] == 'o' ||
  3653. ph[0] == 'u' )
  3654. {
  3655. return true;
  3656. }
  3657. }
  3658. return false;
  3659. }