00001 // VisageLinkDoc.h : interface of the CVisageLinkDoc class 00002 // 00003 ///////////////////////////////////////////////////////////////////////////// 00004 00005 #if !defined(AFX_VISAGELINKDOC_H__5C6AA0DA_63F2_4882_B589_7C56AC7E188B__INCLUDED_) 00006 #define AFX_VISAGELINKDOC_H__5C6AA0DA_63F2_4882_B589_7C56AC7E188B__INCLUDED_ 00007 00008 #if _MSC_VER > 1000 00009 #pragma once 00010 #endif // _MSC_VER > 1000 00011 00012 #include "visagesapi5tts.h" 00013 #include "FAPlayer.h" 00014 #include "AFM.h" 00015 #include "SimpleVORAction.h" 00016 #include "shlwapi.h" 00017 /*! \mainpage visage|SDK VisageLink 00018 * VisageLink demonstrates the following capabilities of <a href="../../../../doc/index.html">visage|SDK</a>: 00019 * - using a SAPI-5 Text-to-Speech engine to generate speech and corresponding face animation and 00020 * render them immediately on the screen 00021 * - using FAPlayer to dynamically insert additional actions (gestures, movements etc.) into the animation based on bookmarks in the input text using the Visagesapi5ttsObserver mechanism 00022 * 00023 * To use the application: 00024 * 00025 * - File->Start loads the virtual character and initializes the animation. Since all file names are hard-coded in this example, it is best to run 00026 * the example in the VisageSDK/Samples/VisageLink folder, where all necessary files are present. If any files 00027 * are missing, error will be reported. 00028 * - File->Speak reads the text from the input file test-sapi5-expression.txt and uses TTS to generate 00029 * speech and animation. Animation is rendered in real time on a face model immediately as it is generared, i.e. during the speech synthesis. 00030 * Bookmarks in the text are interpreted as facial expressions. 00031 * The test-sapi5-expression.txt file includes a surprise expression towards the end 00032 * of animation and a joy expression at the beginning, as well as a crude waving action. 00033 * - Options menu items allow to enable and disable the gaze following, or vestibulo-ocular reflex. When it is enabled, the gaze 00034 * is directed always straight ahead (like the character is watching you) even when the head rotates. 00035 * 00036 * In general, the code works as follows. A base animation track 00037 * (headmotion_short.fba) is loaded and played in a loop by an FAPlayer. This track contains simple head motion. 00038 * A Visagesapi5tts object is attached as an FbaAction to the FAPlayer. Therefore, when Visagesapi5tts::speak() 00039 * method is called, the FAPlayer will play the animation generated by Visagesapi5tts. 00040 * Visagesapi5tts also calls the Visagesapi5ttsObserver callback functions Notify() and BookMark(). These 00041 * functions are implemented in CVisageLinkDoc class, which is an implementation of Visagesapi5ttsObserver. 00042 * In the BookMark() callback 00043 * function we receive the notification of bookmarks inserted into the text. The BookMark() function is called 00044 * when the bookmark is encountered, and this mechanism allows us to insert animation actions at the 00045 * desired time in the speech, e.g. just before a particular word is pronounced. This mechanism is used to 00046 * trigger basic expressions inserted into the text as bookmarks. 00047 * 00048 * All callbacks are implemented in the CVisageLinkDoc class, which 00049 * implements the Visagesapi5ttsObserver abstract class. 00050 * 00051 * This example has initially been generated using the MS Visual C++ 6.0 AppWizard and most of 00052 * it has been generated automatically. Please refer to the <a href="../ReadMe.txt"> ReadMe</a> 00053 * file generated by the AppWizard for the general structure of the program. The code also 00054 * contains plenty of comments generated by the AppWizard. 00055 * 00056 * *****************IMPORTANT*********************************** 00057 * 00058 * This project requires the installation of the Microsoft Speech SDK 5.1, 00059 * and setting the include and library paths accordingly. 00060 * To download Microsoft Speech SDK 5.1 go to http://www.microsoft.com/downloads and search for Speech SDK, version 5.1; download SpeechSDK51.exe. 00061 * 00062 * ************************************************************* 00063 * 00064 * The specific classes and methods that demonstrate visage|SDK are: 00065 * 00066 * - CVisageLinkDoc: Implements the necessary functions of Visagesapi5ttsObserver. 00067 * - CVisageLinkDoc::OnFileStart(): Performs all initialization procedures. 00068 * - CVisageLinkDoc::OnFileSpeak(): Reads the text from the file and speaks it. 00069 * - CVisageLinkDoc::BookMark(): Processes bookmarks in the input text and inserts expressions based on the bookmarks. 00070 * - SimpleFacialExpression: Implements a facial expression action with simple dynamics. 00071 * - CVisageLinkDoc::OnOptionsGazefollowingvor: Enables the gaze following behavior. 00072 */ 00073 00074 /** 00075 * Main document class. 00076 * Implements the necessary functions of FARenderer and Visagesapi5ttsObserver. 00077 */ 00078 class CVisageLinkDoc : public CDocument, public Visagesapi5ttsObserver 00079 { 00080 protected: // create from serialization only 00081 CVisageLinkDoc(); 00082 DECLARE_DYNCREATE(CVisageLinkDoc) 00083 00084 // Attributes 00085 public: 00086 /** 00087 * The FAPlayer. 00088 * The Face Animation Player (FAPlayer). It is used to load and play animation and corresponding sound. 00089 */ 00090 FAPlayer *m_FAPlayer; 00091 00092 /** 00093 * The Visage TTS. 00094 * The TTS object used for speaking. 00095 */ 00096 Visagesapi5tts *vtts; 00097 00098 /** 00099 * The Vestibolo-Ocular Reflex (gaze following) action. 00100 */ 00101 SimpleVORAction *vor; 00102 00103 /** 00104 * Animation started flag. 00105 * This flags indicates that the basic animation is started and everything is initialised and ready for speaking.. 00106 */ 00107 bool animationStarted; 00108 00109 // Operations 00110 public: 00111 BOOL OnOpenDocument(LPCTSTR lpszPathName); 00112 00113 // Overrides 00114 // ClassWizard generated virtual function overrides 00115 //{{AFX_VIRTUAL(CVisageLinkDoc) 00116 public: 00117 virtual BOOL OnNewDocument(); 00118 virtual void Serialize(CArchive& ar); 00119 //}}AFX_VIRTUAL 00120 00121 // Implementation 00122 public: 00123 void Notify (Visagesapi5tts *vtts, FBAPs *faps, CodingParameters *cp, long pts); 00124 void BookMark (Visagesapi5tts *vtts, long qTimeStamp, DWORD dwMarkNum,WCHAR *markText); 00125 void StartSpeech (Visagesapi5tts *vtts, WCHAR *text); 00126 void CVisageLinkDoc::CheckFiles(); 00127 00128 00129 00130 virtual ~CVisageLinkDoc(); 00131 #ifdef _DEBUG 00132 virtual void AssertValid() const; 00133 virtual void Dump(CDumpContext& dc) const; 00134 #endif 00135 00136 protected: 00137 00138 // Generated message map functions 00139 protected: 00140 //{{AFX_MSG(CVisageLinkDoc) 00141 afx_msg void OnFileStart(); 00142 afx_msg void OnFileSpeak(); 00143 afx_msg void OnOptionsGazefollowingvor(); 00144 afx_msg void OnOptionsDisablegazefollowingvor(); 00145 //}}AFX_MSG 00146 DECLARE_MESSAGE_MAP() 00147 private: 00148 int m_iLastRenderedTime; 00149 }; 00150 00151 ///////////////////////////////////////////////////////////////////////////// 00152 00153 //{{AFX_INSERT_LOCATION}} 00154 // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 00155 00156 #endif // !defined(AFX_VISAGELINKDOC_H__5C6AA0DA_63F2_4882_B589_7C56AC7E188B__INCLUDED_)