I changed to Compiler Version 3.3.1-12875-gadf843196a which is what
FPCUPDeluxe installed when I installed Trunk and now it runs just fine.  
So I guess there was a bug in 3.3.1-10077-gc8403ad49e that was fixed
already.   I was so convinced that I was doing something wrong I didn't even
think to try another version.


>Because I use a screen reader, I have multiple sapi voices installed,
(though I rarely use them), but I haven't played with the code enough just
yet to see why it fails when it tries to select one, when not selecting one
works just fine <shrug>

Here's a sample program that now works on the updated 3.3.1, I guess it
should work on 3.2 as well.   It lists all available voices and lets you
choose one.  Maybe that would let you select another voice?

{$Mode OBJFPC}
program VoiceSelection;
uses
  ComObj;

var
  v: OleVariant;
  selectedVoiceIndex: Integer;
  voiceName: string;
  speechText: string;

begin
  v := CreateOleObject('SAPI.SpVoice');

  Writeln('Available Voices:');
  for selectedVoiceIndex := 0 to v.GetVoices.Count - 1 do
  begin
    voiceName := v.GetVoices.Item(selectedVoiceIndex).GetDescription;
    Writeln('Voice ', selectedVoiceIndex + 1, ': ', voiceName);
  end;

  Writeln;
  Writeln('Enter the index of the voice you want to use:');
  Readln(selectedVoiceIndex);

  if (selectedVoiceIndex < 1) or (selectedVoiceIndex > v.GetVoices.Count)
then
  begin
    Writeln('Invalid voice index.');
    Exit;
  end;

  voiceName := v.GetVoices.Item(selectedVoiceIndex - 1).GetDescription;
  v.Voice := v.GetVoices.Item(selectedVoiceIndex - 1);
  Writeln('Selected Voice: ', voiceName);
  speechText := 'Hello World, this is ' + voiceName;
  Writeln('Speech Text: ', speechText);
  v.Speak(speechText);
end.




James

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to