在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
(一)要使用系统的语音库,你需要先安装 Microsoft Speech SDK 5.1 及其语言包,下载地址: Speech SDK 5.1: http://www.newhua.com/soft/38264.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 type var implementation {$R *.dfm} { TForm1 } procedure TForm1.PlayVoxEx; procedure TForm1.Button1Click(Sender: TObject); procedure TForm1.Button3Click(Sender: TObject); end. 我知道的就这么多了, 希望对你有点用...
回答人的补充 2010-03-12 12:25
这边的代码直接复制编译会报错, 需要按 CTRL+H 打开替换框, 复制" "双引号内的字符替换成两个空格(全部替换), 再编译就行了.
回答人的补充 2010-03-12 12:31
procedure TForm1.Button3Click(Sender: TObject); 改成: procedure TForm1.Button3Click(Sender: TObject);
提问人的追问 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代表英文。 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论