델파이에서 MS Speech-API(SAPI) 사용
사용법
TSpVoice, TSpObjectToken 클래스 필요
위 설치후 ActiveX에서 추가함
목소리 받아오기
목소리 목록을 받아서 콤보에 설정함.
procedure TfConfig.FormCreate(Sender: TObject);
var
SOTokenVoice: ISpeechObjectToken; // See the MS SAPI SDK for info on
SOTokenVoices:ISpeechObjectTokens; // registry tokens that hold resources
i: Integer;
begin
SpVoice1.EventInterests := SVEAllEvents;
SOTokenVoices := SpVoice1.GetVoices('',''); // Use the registry tokens
for I := 0 to SOTokenVoices.Count - 1 do
begin
//For each voice, store the descriptor in the TStrings list
SOTokenVoice := SOTokenVoices.Item(i);
ComboBoxVoices.Items.AddObject(SOTokenVoice.GetDescription(0), TObject(SOTokenVoice));
//Increment descriptor reference count to ensure it's not destroyed
SOTokenVoice._AddRef;
end;
if ComboBoxVoices.Items.Count > 0 then
begin
ComboBoxVoices.ItemIndex := ComboBoxVoices.Items.IndexOf(SpVoice1.Voice.GetDescription(0));
end;
// 볼륨설정
TrackBarVolume.Position := SpVoice1.Volume;
end;
목소리 콤보 선택에 따른 목소리 설정
procedure TfConfig.ComboBoxVoicesChange(Sender: TObject);
var SOTokenVoice: ISpeechObjectToken;
begin
SOTokenVoice := ISpeechObjectToken(Pointer(ComboBoxVoices.Items.Objects[ComboBoxVoices.ItemIndex]));
SpVoice1.Voice := SOTokenVoice;
end;
Text To Speech
procedure TfConfig.Speak(Text: String);
var
iSpeechFlags: Integer = SVSFlagsAsync + SVSFPurgeBeforeSpeak + SVSFIsXML;
begin
if SpVoice1.Voice = nil then exit;
SpVoice1.Speak(Text, iSpeechFlags);
end;
댓글