delphi调用windows自带语音功能

windows自带语音接口 SAPI.SpVoice, 接口说明如下

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee125663(v%3dvs.85)

简单调用代码:

uses
  System.Win.ComObj;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  lO: OleVariant;
begin
  lO := CreateOleObject('SAPI.SpVoice');
  {设置语音库 男/女 中文/英文支持, 这句可以不要, 使用默认语音库}
  lO.Voice := lO.GetVoices('name=Microsoft David Desktop', '').Item(0);
  {语音播报}
  lO.Speak(Memo1.Lines.Text);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  lO, lV, lX: OleVariant;
  x: integer;
begin
  {获取系统语音库}
  lO := CreateOleObject('SAPI.SpVoice');
  lV := lO.GetVoices;
  for x := 0 to lV.count - 1 do
  begin
    lX := lV.item(x);
    memo1.Lines.Add(lX.GetDescription);
  end;
end;

 

posted on 2018-11-28 11:38  黑暗煎饼果子  阅读(1294)  评论(0编辑  收藏  举报