Delphi7怎么样调用系统语音库 .

(一)要使用系统的语音库,你需要先安装 Microsoft Speech SDK 5.1 及其语言包,下载地址:

Speech SDK 5.1: http://www.newhua.com/soft/38264.htm
Speech SDK 5.1 语言包(中英文): http://www.onlinedown.net/soft/38265.htm

 

(二)安装完成后,需要在D7里导入类库以便生成SAPI组件于IDE组件面板.

启动D7, Project -> Import Type Library->找到Microsoft Speech Object Library (Version 5.0)

点Install..

 

成功后会在D7的组件面板里出现 SAPI 5.1 控件页.

(三)OK,开始来个简单的工程.

启动D7新建个工程,往窗口里扔进一个TMemo,两个TButton,再扔进一个TSpVoice(SAPI 5.1控件页),写下下边的代码:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleServer, SpeechLib_TLB, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
SpVoice1: TSpVoice;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
procedure PlayVoxEx;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.PlayVoxEx;
var
 i: Integer;
 s,t: String;
begin
 s:=Memo1.Text;
 for i:=1 to Length(s) do
 begin
  if not (s[i] in [#10,#13]) then
  begin
   if ByteType(s, i)=mbSingleByte then
    begin
     SpVoice1.Voice:=SpVoice1.GetVoices('','').Item(0); //设置报读的语种,0为英文,3为中文
     t:=s[i];
    end
   else if ByteType(s, i)=mbLeadByte then
    begin
     SpVoice1.Voice:=SpVoice1.GetVoices('','').Item(3);
     t:=s[i];
     t:=s[i]+s[i+1];
    end
   else
    continue;
   SpVoice1.Speak(t, SVSFlagsAsync); //读出Text
  end;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 SpVoice1.Voice:=SpVoice1.GetVoices('','').Item(3);
 SpVoice1.Speak(Memo1.Text, SVSFlagsAsync);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
 SpVoice1.Voice:=SpVoice1.GetVoices('','').Item(0);
 SpVoice1.Speak(Memo1.Text, SVSFlagsAsync);
end;

end.

Button1是直接读中文语音的,Button2可以读中英文混合(效果相当差),Button3直接读英文用的

我知道的就这么多了, 希望对你有点用...

回答人的补充   2010-03-12 12:25
这边的代码直接复制编译会报错, 需要按 CTRL+H 打开替换框, 复制" "双引号内的字符替换成两个空格(全部替换), 再编译就行了.
回答人的补充   2010-03-12 12:31

procedure TForm1.Button3Click(Sender: TObject);
begin
 SpVoice1.Voice:=SpVoice1.GetVoices('','').Item(0);
 SpVoice1.Speak(Memo1.Text, SVSFlagsAsync);
end;

改成:

procedure TForm1.Button3Click(Sender: TObject);
begin
 PlayVoxEx;
end;

提问人的追问   2010-03-18 14:06

安装成功之后再那里能找到TSpVoice ,我安装了之后再Delphi7里面多了这个页面  也不知道安装的对不对

 

回答人的补充   2010-03-18 18:33
dclusr.dpk是缺省的用户安装控件包, 多出来的应该是你之前安装到dclusr.dpk包里的一些别的控件... 在导入ActiveX那个界面里点Install后,你可以选 Into new package , 然后浏览一个目录填个包名再返回安装就不会有这些东西了.
TTS语音程序以下是全部源码,基本功能以实现
   unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,VTxtAuto_TLB, StdCtrls, Buttons, OleServer, SpeechLib_TLB,
ComCtrls;type
TForm1 = class(TForm)
    SpVoice1: TSpVoice;
    BitBtn1: TBitBtn;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    ComboEngine: TComboBox;
    Button4: TButton;
    StatusBar1: TStatusBar;
    BitBtn6: TBitBtn;
    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);
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 thenSpVoice1.Volume:=SpVoice1.Volume+1;
end;procedure TForm1.BitBtn4Click(Sender: TObject);
begin
if SpVoice1.Volume>0 thenSpVoice1.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;  
end.

中英文混读方法  

    正常情况下,当一篇中文文档中有英文,并选择中文语音朗读时,英文朗读效果可能不理想;或者,一篇英文文档中有中文,选择英文语音朗读时,中文将无法朗读出来。解决的办法就是在文档中添加中英文语音标记(标记为:<lang langid="XXX"></lang>,在实际朗读中不会读出来),例如: <lang langid="804">中文句子</lang> 以上"中文句子"会强制用中文语音朗读 <lang langid="409">english sentenses</lang> 以上"english sentenses"会强制用英文语音朗读 标记中804代表中文,409代表英文。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi中英文语音朗读程序(控件及源码)调试OK 先安装Microsoft Speech SDK 5.1,这是微软的声音支持控件 前面安装不多做介绍,一步一步安装即可 安装完成后,需要加载Delphi控件 在Delphi IDE中选择菜单Project,Import Type Library—点击按钮Add(C:\Program Files\Common Files\Microsoft Shared\Speech\ sapi.dll)—点击按钮Install-在Install对话框中点击按钮OK—在Confirm对话框中点击按钮Yes—在对话框中点击按钮OK。至此,共19个控件被添加到Delphi组件板ActiveX页上。其中spvoice控件是我们要使用的 Microsoft Speech SDK 5.1下载地址:http://intraweb.5d6d.com/thread-280-1-1.html SpVoice详解 属性 描述 AlertBoundary 取得或设置停顿分界线。 AllowAudioOutputFormatChangesOnNextSet 设置是否允许声音自动调整到合适状态以适应其音频输出。 AudioOutput .取得或设置当前声音使用的的音频输出对象 AudioOutputStream 取得或设置当前声音使用的的音频输出流对象。 EventInterests 取得或设置当前声音返回的事件类型。 Priority 取得或设置声音的优先级。 Rate 取得或设置阅读的速度。 Status 返回一个ISpeechVoiceStatus 对象用于显示当前阅读和事件的状态 SynchronousSpeakTimeout 取得或设置一个时间间隔,用于标识多久未获得一个输出设备后,一个同步的Speak 和SpeakStream将终止,以毫秒计算。 Voice 取得或设置发音对象。 Volume 取得或设置声音的大小 。 方法 描述 DisplayUI 是否在控制面板中展示详细设置。 GetAudioOutputs 返回一个可用的音频输出标记。 GetVoices 返回一个可用的发音对象。 IsUISupported 决定是否能通过控制棉板的音频设置来控制。 Pause 暂停朗读。. Resume 恢复暂停,继续播放。 Skip 在当前输入的文本流中向前或向后跳一定距离再播放。 Speak 阅读一个字符串。 SpeakCompleteEvent 得到一个朗读完毕的时间句柄 SpeakStream 朗读一个文本流或一个声音文件。 WaitUntilDone 阻塞进程,直到声音播放完毕或者超时。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值