以前利用TTS做过一个自动制作英语单词MP3并且生成同步解释LRC的小程序,下面简单介绍一下TTS的使用,希望对你有帮助,欢迎交流。
要开发TTS程序,首先要安装语音SDK,下面是具体步骤:
1.安装speechsdk51.exe (http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/speechsdk51.exe)
2.安装speechsdk51LangPack.exe
(http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-
US/speechsdk51LangPack.exe)
3.启动Delphi7
4.安装了sdk5.1后,在Delphi里面Project->Import Type Library对话框里会有一个
Micosoft Speech Object Library(Version5.1)(或者Version5.0)的ActiveX组件,install...。按提示安装好,ActiveX下面就多出一组控件。
5.新建Application,放置Edit(输入要朗读的内容)、ComboBox(列出系统安装的语音库)、
ScrollBar(设置朗读速度)、Label(显示朗读速度)各一个。
ScrollBar设置Max:10,Min:-10。
uses中加入SpeechLib_TLB,定义变量MySpeech:SpVoice。
后面附源码和注释,只列举了基本的功能,详细的功能请参考sapi.chm
(http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/sapi.chm)。
注意:朗读英文时要选择英文朗读者,朗读中文要选择中文朗读者(Microsoft Simplified
Chinese)。Vista自带的中文语音库可以中英文混合朗读,并且效果不错。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SpeechLib_TLB;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
ComboBox1: TComboBox;
ScrollBar1: TScrollBar;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure ScrollBar1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MySpeech:SpVoice;
//定义
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
MySpeech:=coSpVoice.Create;
//创建
for i:=0 to MySpeech.GetVoices('','').Count-1do
//获取系统安装的语音引擎
begin
ComboBox1.Items.add(MySpeech.GetVoices('','').Item(i).GetDescription(0));
if ComboBox1.Items.Count<>0 then
ComboBox1.ItemIndex:=0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MySpeech.Speak(Edit1.Text, SVSFlagsAsync);
// SVSFlagsAsync,异步方式朗读
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
MySpeech._set_Voice(MySpeech.GetVoices('','').Item(ComboBox1.ItemIndex));
//设置语音朗读者
end;
procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
Label1.Caption:=IntToStr(Scrollbar1.Position);
MySpeech.Set_Rate(Scrollbar1.Position);
//设置朗读速度
end;
end.