码迷,mamicode.com
首页 > Windows程序 > 详细

delphi 播放语音

时间:2019-01-17 12:48:21      阅读:746      评论:0      收藏:0      [点我收藏+]

标签:control   dial   wav   lib   release   lease   .text   cli   pre   

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  SpeechLib_TLB;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    procedure PlaywavByStrs(pvWavStr: string; SVSFlagsAsync: Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  fVoce: ISpeechVoice;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  PlaywavByStrs(Edit1.Text, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  fVoce := CoSpVoice.Create;
  fVoce.Resume;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  fVoce._Release;
end;

procedure TForm1.PlaywavByStrs(pvWavStr: string; SVSFlagsAsync: Integer);
begin
  if fVoce.Status.RunningState = SRSEDone then
    fVoce.Speak(pvWavStr, SVSFlagsAsync);
end;

end.

需要引用SpeechLib_TLB.pas 文件

delphi 播放语音

标签:control   dial   wav   lib   release   lease   .text   cli   pre   

原文地址:https://www.cnblogs.com/yangxuming/p/10281459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!