Leaked source code of windows server 2003
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.

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