Using TTS with Delphi
https://en.wikipedia.org/wiki/Microsoft_Speech_API
https://en.wikipedia.org/wiki/SASDK
CreateOLEObject('SAPI.SpVoice');
voz := CreateOLEObject('SAPI.SpVoice');
if not VarIsEmpty(voz) then begin
vozes := voz.getVoices;
ComboVoz.Clear;
for i := 0 to vozes.Count - 1 do
ComboVoz.Items.Add(vozes.item(i).GetDescription);
Dialogs, StdCtrls, SpeechLib_TLB, OleServer, XPMan, ExtCtrls, ComCtrls, ENGINE,
TFlatCheckBoxUnit;
SAPI: TSpVoice;
PropriedsF: TPropriedsF;
SOTokenVoice: ISpeechObjectToken; // See the MS SAPI SDK for info on
SOTokenVoices:ISpeechObjectTokens; // registry tokens that hold resources
VPT:= 'Você selecionou X como voz padrão do sistema.';
SAPI.EventInterests := SVEAllEvents;
SOTokenVoices := SAPI.GetVoices('',''); // Use the registry tokens
//For each voice, store the descriptor in the TStrings list
SOTokenVoice := SOTokenVoices.Item(i);
CBFA.Items.AddObject(SOTokenVoice.GetDescription(0), TObject(SOTokenVoice));
//Increment descriptor reference count to ensure it's not destroyed
SOTokenVoice._AddRef;
CBFA.ItemIndex := CBFA.Items.IndexOf(SAPI.Voice.GetDescription(0));
TB.Position := SAPI.Rate;
EDTEST.TEXT:= TROCA('X', SAPI.Voice.GetDescription(0), VPT);
var SOTokenVoice: ISpeechObjectToken;
begin
SOTokenVoice := ISpeechObjectToken(Pointer(CBFA.Items.Objects[CBFA.ItemIndex]));
SAPI.Voice := SOTokenVoice;
EDTEST.TEXT:= TROCA('X', SAPI.Voice.GetDescription(0), VPT);
if SAPI.Voice = nil then
SAPI.Speak(EDTEST.Text, 1);
SpFileStream1: TSpFileStream;
FileName : TFileName;
T: TSTRINGLIST;
I: INTEGER;
T:= TSTRINGLIST.CREATE;
T.LoadFromFile(EXTRACTFILEPATH(PARAMSTR(0))+'LISTA.TXT');
FileName := extractfilepath(paramstr(0))+'RAQUEL\'+T[I];
SpFileStream1 := TSpFilestream.Create(nil);
SpFileStream1.Open(FileName, SSFMCreateForWrite, False);
SAPI.AudioOutputStream := SPFileStream1.DefaultInterface;
SAPI.Speak(COPY(T[I], 1, POS('.', T[I])-1), SVSFDefault);
SPFileStream1.Close;
SpFileStream1.Free;
procedure TForm1.FormClick(Sender: TObject);
var
SpVoice: Variant;
begin
SpVoice := CreateOleObject('SAPI.SpVoice');
SpVoice.Speak('this is a test', 0);
end;
SpVoice GetVoices method (SAPI 5.3) | Microsoft Docs
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, SpeechLib_TLB,ActiveX, ComCtrls,ControlCenter;
SpVoice1: TSpVoice;
SpSharedRecoContext1: TSpSharedRecoContext;
ProgressBar1: TProgressBar;
SRGrammar: ISpeechRecoGrammar;
CmdLine:string;
ControlActive:Boolean;
adeSoundControl: TadeSoundControl;
SOToken: ISpeechObjectToken;
SOTokens: ISpeechObjectTokens;
SOTokens := SpVoice1.GetVoices('', '');
SOToken := SOTokens.Item(id);
SpVoice1.Voice := SOToken;
SpVoice1.Rate:=speech;
SpVoice1.Volume:=100;
spvoice1.Speak(str,SVSFDefault);
Speecker(StrToInt(Edit2.Text),StrToInt(Edit3.Text),Edit1.Text);
https://github.com/halilhanbadem/delphi-google-speech-to-text
https://www.youant.net/
https://github.com/SirAlex/delphi-jose-jwt
Delphi JOSE and JWT Library
https://github.com/grijjy/DelphiGoogleAPI
Using the Google Cloud Platform APIs
voice: OLEVariant;
voice := CreateOLEObject ('SAPI.SpVoice');
voice.Voice := voice.GetVoices.Item(combobox1.ItemIndex); // current voice selected
voice.volume := tbVolume.position;
voice.rate := tbRate.position;
voice.Speak (s, SVSFDefault);
voice.Speak (s, SVSFlagsAsync);
repeat Sleep(100); until voice.WaitUntilDone(10);
TMainForm = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
voice: OLEVariant;
procedure SayIt(const s:string);
end;
var
MainForm: TMainForm;
implementation
uses
ComObj;
{$R *.dfm}
procedure TMainForm.SayIt(const s:string); // s is the string to be spoken
const
SVSFDefault = 0;
SVSFlagsAsync = 1;
SVSFPurgeBeforeSpeak= 2;
begin
memo1.setfocus;
voice.Voice := voice.GetVoices.Item(combobox1.ItemIndex); // current voice selected
voice.volume := tbVolume.position;
voice.rate := tbRate.position;
voice.Speak (s, SVSFlagsAsync {or SVSFPurgeBeforeSpeak});
end;
procedure TMainForm.Button1Click(Sender: TObject);
begin
SayIt('Hello');
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
voice := CreateOLEObject('SAPI.SpVoice');
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
voice := Unassigned;
end;
end.
https://stackoverflow.com/questions/12117883/sapi-with-dephi-async-speech-doesnt-work
https://github.com/kimond/Jarvis-Project/blob/master/pyttsx/drivers/sapi5.py
MSSAM = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\MSSam'
MSMARY = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\MSMary'
MSMIKE = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\MSMike'
MSSam MSMary MSMike
http://www.blong.com/conferences/dcon2002/speech/SAPI51/SAPI51.htm
https://edn.embarcadero.com/article/29583
Speech Synthesis & Speech Recognition: Using SAPI 5.1
procedure TfrmTextToSpeech.FormCreate(Sender: TObject);
var
I: Integer;
SOToken: ISpeechObjectToken;
SOTokens: ISpeechObjectTokens;
begin
SendMessage(lstProgress.Handle, LB_SETHORIZONTALEXTENT, Width, 0);
//Ensure all events fire
SpVoice.EventInterests := SVEAllEvents;
Log('About to enumerate voices');
SOTokens := SpVoice.GetVoices('', '');
for I := 0 to SOTokens.Count - 1 do
begin
//For each voice, store the descriptor in the TStrings list
SOToken := SOTokens.Item(I);
cbVoices.Items.AddObject(SOToken.GetDescription(0), TObject(SOToken));
//Increment descriptor reference count to ensure it's not destroyed
SOToken._AddRef;
end;
if cbVoices.Items.Count > 0 then
begin
cbVoices.ItemIndex := 0; //Select 1st voice
cbVoices.OnChange(cbVoices); //& ensure OnChange triggers
end;
Log('Enumerated voices');
Log('About to check attributes');
tbRate.Position := SpVoice.Rate;
lblRate.Caption := IntToStr(tbRate.Position);
tbVolume.Position := SpVoice.Volume;
lblVolume.Caption := IntToStr(tbVolume.Position);
Log('Checked attributes');
end;
沒有留言:
張貼留言