Jouke Visser


Win32::SAPI5 - Perl interface to the Microsoft Speech API 5.1


    use Win32::SAPI5;
    my $object = Win32::SAPI5::SpVoice->new();
    my $object = Win32::SAPI5::SpNotifyTranslator->new();
    my $object = Win32::SAPI5::SpObjectTokenCategory->new();
    my $object = Win32::SAPI5::SpObjectToken->new();
    my $object = Win32::SAPI5::SpResourceManager->new();
    my $object = Win32::SAPI5::SpStreamFormatConverter->new();
    my $object = Win32::SAPI5::SpMMAudioEnum->new();
    my $object = Win32::SAPI5::SpMMAudioIn->new();
    my $object = Win32::SAPI5::SpMMAudioOut->new();
    my $object = Win32::SAPI5::SpRecPlayAudio->new();
    my $object = Win32::SAPI5::SpStream->new();
    my $object = Win32::SAPI5::SpSharedRecoContext->new();
    my $object = Win32::SAPI5::SpInprocRecognizer->new();
    my $object = Win32::SAPI5::SpSharedRecognizer->new();
    my $object = Win32::SAPI5::SpLexicon->new();
    my $object = Win32::SAPI5::SpUnCompressedLexicon->new();
    my $object = Win32::SAPI5::SpCompressedLexicon->new();
    my $object = Win32::SAPI5::SpPhoneConverter->new();
    my $object = Win32::SAPI5::SpNullPhoneConverter->new();
    my $object = Win32::SAPI5::SpTextSelectionInformation->new();
    my $object = Win32::SAPI5::SpPhraseInfoBuilder->new();
    my $object = Win32::SAPI5::SpAudioFormat->new();
    my $object = Win32::SAPI5::SpWaveFormatEx->new();
    my $object = Win32::SAPI5::SpInProcRecoContext->new();
    my $object = Win32::SAPI5::SpCustomStream->new();
    my $object = Win32::SAPI5::SpFileStream->new();
    my $object = Win32::SAPI5::SpMemoryStream->new();


This module is a simple interface to the Microsoft Speech API 5.1 There are interfaces to all classes that this API consists of. The constructors return Win32::OLE objects, on which you can call all methods and get/set all properties.

This documentation won't offer the complete documentation for it, just download the Microsoft Speech API 5.1 SDK and read the part of the documentation that covers 'Automation' (since we're using the Automation Object interface.


The Microsoft Speech API 5.1. It can be downloaded for free from (go to the 'old versions' and find the 5.1 version)


See the Microsoft Speech API 5.1 documentation that comes with the SDK, except for the following utility methods available for Win32::SAPI5::SpVoice:



This is the constructor for each and every Win32::SAPI5 subclass. It does not take any parameters


All classes support the GetObject method, which will return the actual Win32::OLE object. This can be useful when you need to pass the object itself as a parameter to a method of another object.

for example:

  # setup Microsoft Speech API
  my $stream = Win32::SAPI5::SpFileStream->new();
  $stream->Open($wav, 3, 0); # 3 = SSFMCreateForWrite

  my $voice = Win32::SAPI5::SpVoice->new();
  $voice->SetProperty(AudioOutputStream => $stream->GetObject);


To be somewhat compatible with Win32::SAPI4::VoiceText, I've added the utilitymethods that exist there to Win32::SAPI5::SpVoice, to be able to apply the same code to this API.


This method returns a list of all installed languages with their countryname. It may look like ('Dutch (Netherlands)', 'Dutch (Belgium)', 'English (United States)', 'Portuguese (Brazil)'). Some speechengines might not return a languageID. In this case 'unknown' is returned.


This method takes a language as returned by GetInstalledLanguages and returns a list of all installed voices with their language. It may look like ('Adult female (Dutch)', 'Microsoft Sam (US English)')


This method takes a language as returned by GetInstalledLanguages and returns the corresponding LanguageID that SpVoice knows. This also converts the 'unknown' that might be returned by GetInstalledLanguages back to a 0.


This method takes a voice as returned by GetInstalledVoices and returns the corresponding ModeID that SpVoice knows.


The Microsoft SAPI 5.1 SDK is supported on news://microsoft.public.speech_tech.sdk You can email the author for support on this module.


        Jouke Visser


Copyright (c) 2004 Jouke Visser. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.


perl(1), Microsoft Speech API 5.1 documentation.