⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 我自己写的DELPHI 调用语音库朗读的例子, 有完整的代码. 我的QQ: 740203690 已经应用我的顺时针写作软件里了.
💻 PAS
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,SpeechLib_TLB, StdCtrls, Buttons, OleServer,
ComCtrls;
type
TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    SpVoice1: TSpVoice;
    ComboEngine: TComboBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    StatusBar1: TStatusBar;
    BitBtn5: TBitBtn;
    Memo1: TMemo;
    Label1: TLabel;
    procedure BitBtn1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure ComboEngineCloseUp(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;
var
Form1: TForm1;
//tts:IVTxtAuto;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
SpVoice1.Speak(Memo1.Lines.Text,SPFM_CREATE_ALWAYS);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SpVoice1.Pause;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SpVoice1.Resume;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if SpVoice1.Rate<10 then

SpVoice1.Rate:=SpVoice1.Rate+1;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
if SpVoice1.Rate>-10 then
SpVoice1.Rate:=SpVoice1.Rate-1;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
// 音量
if SpVoice1.Volume<100 then
SpVoice1.Volume:=SpVoice1.Volume+1;
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
begin
if SpVoice1.Volume>0 then
SpVoice1.Volume:=SpVoice1.Volume-1;
end;
procedure TForm1.BitBtn5Click(Sender: TObject);
var  
      Sots1:ISpeechObjectTokens;  
      Sot1:ISpeechObjectToken;  
      i:integer;
begin  
      SpVoice1.EventInterests   :=   SVEAllEvents;
      Sots1:=SpVoice1.GetVoices('','');
      ComboEngine.Clear;
      for   i   :=   0   to   Sots1.Count-1   do  
          begin  
                Sot1:=Sots1.Item(i);  
                ComboEngine.Items.Add(Sot1.GetDescription(0));  
          end;  
          begin  
                  if   ComboEngine.Items.Count   >   0   then
                      begin  
                          if   ComboEngine.Items.IndexOf('Microsoft   Simplified   Chinese')=-1   then
                                  ComboEngine.ItemIndex   :=   0  
                          else
                                  ComboEngine.ItemIndex   :=   ComboEngine.Items.IndexOf('Microsoft   Simplified   Chinese');  
                      end;  
          end;  
end;  

procedure TForm1.Button4Click(Sender: TObject);
var     //设置可用引擎
          Sots1:ISpeechObjectTokens;  
          Sot1:ISpeechObjectToken;
begin
      if   ComboEngine.Itemindex=-1   then   Exit;
      Sots1:=SpVoice1.GetVoices('','');  
      Sot1:=Sots1.Item(ComboEngine.Itemindex);  
   
      SpVoice1.Voice:=Sot1;
   // StatusBar1.Panels[0].Text:='朗读引擎:'+ComboEngine.Items.Strings[ComboEngine.Itemindex];
end;

procedure TForm1.ComboEngineCloseUp(Sender: TObject);
var     //设置可用引擎
          Sots1:ISpeechObjectTokens;  
          Sot1:ISpeechObjectToken;
begin
      if   ComboEngine.Itemindex=-1   then   Exit;
      Sots1:=SpVoice1.GetVoices('','');  
      Sot1:=Sots1.Item(ComboEngine.Itemindex);  
   
      SpVoice1.Voice:=Sot1;

end;

end.








⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -