1. 程式人生 > >delphi呼叫windows自帶語音功能

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;