日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi 播放wav声音

發布時間:2023/12/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delphi 播放wav声音 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. uVar.pas單元如下

unit uVar;interfaceusesSysUtils, Forms;typeTAppPara = classpublicclass function AppPath: string;class function AppName: string;end;TFilePath = class(TAppPara)publicclass function VoicePath: string;end;implementation{ TFilePath }class function TFilePath.VoicePath: string; beginResult := AppPath + 'voice\'; end;{ TAppPara }class function TAppPara.AppName: string; beginResult := ExtractFileName(Application.ExeName); end;class function TAppPara.AppPath: string; beginResult := ExtractFilePath(Application.ExeName); end;end.

2. uVoice.pas單元如下

unit uVoice;interfaceusesSysUtils, MMSystem;constFileExt= '.wav';type//播放wav文件TVoice= classprivateFFilePath: string; //wav文件目錄publicproperty _FilePath: string read FFilePath write FFilePath;constructor Create(sPath: string);destructor Destroy; override;function Play(sFile: string): Boolean;end;implementation{ TVoice }constructor TVoice.Create(sPath: string); beginFFilePath:= sPath; end;destructor TVoice.Destroy; begininherited; end;function TVoice.Play(sFile: string): Boolean; varfilename: string; beginResult:= False;tryfilename:= FFilePath+ sFile+ FileExt;if FileExists(filename) thenResult:= sndPlaySound(PChar(filename), SND_NODEFAULT+ SND_ASYNC);{SND_ASYNC 用異步方式播放聲音SND_LOOP 播放載入到內存中的聲音SND_MEMORY 播放載入到內存中的聲音SND_NODEFAULT 不播放缺省聲音SND_NOWAIT 如果驅動程序正忙則函數就不播放聲音并立即返回SND_PURGE 停止所有的聲音SND_SYNC 同步播放聲音,在播放完后PlaySound函數才返回}finally//end; end;end.

3. uFrmMain.pas如下

unit uFrmMain;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, OleServer, SpeechLib_TLB, StdCtrls, uVoice;typeTFrmMain = class(TForm)Button1: TButton;Button2: TButton;Label1: TLabel;Edit1: TEdit;SpVoice1: TSpVoice;procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure FormCreate(Sender: TObject);procedure FormDestroy(Sender: TObject);private{ Private declarations }FVoice: TVoice;public{ Public declarations }end;varFrmMain: TFrmMain;implementationuses uVar;{$R *.dfm}procedure TFrmMain.Button1Click(Sender: TObject); varsName: string; begin//語音文件名sName:= '歡迎光臨';if Assigned(FVoice) thenFVoice.Play(sName); end;procedure TFrmMain.Button2Click(Sender: TObject); varsName: string; begin//可能有問題 // sName:= Trim(Edit1.Text); // SpVoice1.Speak(sName, SVSFlagsAsync); end;procedure TFrmMain.FormCreate(Sender: TObject); beginFVoice:= TVoice.Create(TFilePath.VoicePath); end;procedure TFrmMain.FormDestroy(Sender: TObject); beginFreeAndNil(FVoice); end;end.

4. 工程文件

program DelphiVoice;usesForms,uFrmMain in 'uFrmMain.pas' {FrmMain},uVoice in 'uVoice.pas',uVar in 'uVar.pas';{$R *.res}beginApplication.Initialize;Application.MainFormOnTaskbar := True;Application.CreateForm(TFrmMain, FrmMain);Application.Run; end.

?

總結

以上是生活随笔為你收集整理的Delphi 播放wav声音的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。