www.pudn.com > c++builerTTS_Test.rar > Unit1.cpp


//--------------------------------------------------------------------------- 
#include  
#pragma hdrstop 
 
#include "Unit1.h" 
#include "wstring.h" 
#include "VTxtAuto_TLB.h" 
//--------------------------------------------------------------------------- 
#pragma package(smart_init) 
#pragma resource "*.dfm" 
TForm1 *Form1; 
IVTxtAuto *IVTxtAuto1; 
//--------------------------------------------------------------------------- 
__fastcall TForm1::TForm1(TComponent* Owner) 
        : TForm(Owner) 
{ 
} 
//--------------------------------------------------------------------------- 
//Project.cpp 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::FormCreate(TObject *Sender) 
{ 
     WideString a = "Demo1"; 
    WideString b = "Project1.exe"; 
    WideString c="";//"Hi,I am trying to speak to you,Do you hear me?"; 
 
    IVTxtAuto1 = NULL; 
    CoInitialize(NULL); 
    OleCheck(CoCreateInstance(CLSID_VTxtAuto_,0,CLSCTX_ALL,IID_IVTxtAuto, (LPVOID*)&IVTxtAuto1)); 
    IVTxtAuto1->Register(a,b); 
    IVTxtAuto1->set_Enabled(1); 
    IVTxtAuto1->set_Speed(150); 
    IVTxtAuto1->Speak(c,vtxtst_STATEMENT); //vtxtsp_VERYHIGH 
    //IVTxtAuto1->AudioRewind(); 
    //IVTxtAuto1->AudioFastForward(); 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::Button1Click(TObject *Sender) 
{ 
    if(IVTxtAuto1 != NULL) 
    { 
      IVTxtAuto1->Speak((WideString)Edit1->Text,vtxtsp_VERYHIGH); 
      //ShowMessage("OK");    //我的调试语句(没声卡) 
    }else{ 
      ShowMessage("服务器没有初始化成功"); 
    } 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::Button2Click(TObject *Sender) 
{ 
    if(IVTxtAuto1 != NULL) 
    { 
      IVTxtAuto1->Speak(   (WideString)Edit1->Text, vtxtst_READING /*vtxtsp_HIGH*/); 
      //ShowMessage("OK");    //我的调试语句(没声卡) 
    }else{ 
      ShowMessage("服务器没有初始化成功"); 
    } 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::Button3Click(TObject *Sender) 
{ 
    if(IVTxtAuto1 != NULL) 
    { 
      IVTxtAuto1->Speak((WideString)Edit1->Text, vtxtst_COMMAND /*vtxtst_SPREADSHEET*/); 
      //ShowMessage("OK");    //我的调试语句(没声卡) 
    }else{ 
      ShowMessage("服务器没有初始化成功"); 
    } 
} 
//--------------------------------------------------------------------------- 
 
/* 
 
  unit   word1;    
     
  interface    
     
  uses    
      Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,    
      VTxtAuto_TLB,   StdCtrls,   ComCtrls,   Mask,   FileCtrl;    
     
  type    
      TForm1   =   class(TForm)    
          speedtext:   TStaticText;    
          speed:   TTrackBar;    
          Button1:   TButton;    
          Edit1:   TEdit;    
          Button2:   TButton;    
          gettext:   TLabel;    
          procedure   FormCreate(Sender:   TObject);    
          procedure   stopbtnClick(Sender:   TObject);    
          procedure   speedChange(Sender:   TObject);    
          procedure   prebtnClick(Sender:   TObject);    
          procedure   nextbtnClick(Sender:   TObject);    
          procedure   FormDestroy(Sender:   TObject);    
          procedure   Button1Click(Sender:   TObject);    
          procedure   Button2Click(Sender:   TObject);    
          procedure   Edit1KeyPress(Sender:   TObject;   var   Key:   Char);    
     
      private    
          {   Private   declarations   }    
      public    
          {   Public   declarations   }    
      end;    
     
  var    
      Form1:   TForm1;    
      TTS:IVTxtAuto;    
  implementation    
     
  {$R   *.DFM}    
     
  procedure   TForm1.FormCreate(Sender:   TObject);    
  begin 
      TTS:=CoVtxtAuto_.Create; 
      TTS.Register('superwords','superwords'); 
      speed.Position:=TTS.Get_Speed; 
      speedtext.caption:='速度:'+inttostr(speed.position); 
      speed.SelEnd:=speed.Position; 
      //filelistbox1.Mask:=   '所有文件(*.*)|*.*|   文本文件(*.txt)|*.txt'; 
  end;    
     
     
     
  procedure   TForm1.stopbtnClick(Sender:   TObject);    
  begin    
      TTS.StopSpeaking;    
  end;    
     
     
  procedure   TForm1.speedChange(Sender:   TObject);    
  begin    
      TTS.Set_Speed(speed.position);    
      speedtext.caption:='速度:'+inttostr(speed.position);    
      speed.SelEnd:=speed.Position;    
  end;    
     
  procedure   TForm1.prebtnClick(Sender:   TObject);    
  begin    
      TTS.AudioRewind;    
  end;    
     
  procedure   TForm1.nextbtnClick(Sender:   TObject);    
  begin    
      TTS.AudioFastForward;    
  end;    
     
  procedure   TForm1.FormDestroy(Sender:   TObject);    
  begin    
      TTS:=nil;    
  end;    
     
  procedure   TForm1.Button1Click(Sender:   TObject);    
  begin    
      close;    
  end;    
     
     
     
     
  procedure   TForm1.Button2Click(Sender:   TObject);    
  begin    
      TTS.Speak(Edit1.text,vtxtst_READING);    
  end;    
     
  procedure   TForm1.Edit1KeyPress(Sender:   TObject;   var   Key:   Char);    
  begin    
      if   (length(trim(edit1.text))>0)   and   (key=chr(32))    
      then     begin   if     trim(edit1.text)=gettext.Caption    
                              then       begin    
                                            TTS.Speak(edit1.Text,vtxtst_COMMAND);    
                                            edit1.Clear;    
                                            end    
                              else       TTS.Speak('YOU   ARE   WRONG',vtxtst_STATEMENT);    
                  end;    
  end;    
     
     
  end.    
*/