Is it even possible to use TTS in ABAP coding ?

Yes and it’s quite easy to do with SAPI.

Let’s look.

While we’re using SAP GUI on windows systems we can use Speech Application Programming Interface provided by Microsoft.

Part of this SAPI is Text-to-Speech and we will use it through OLE Automation.

ABAP Set of instructions designed to support OLE Automation is all we need.

 

In first report we will just try to say something.

I choose two important parameters which controls tts – Rate na Volume.

Adjusting ‘Rate’ property we can force slower or faster text reading.

Whereas ‘Volume’ changing only power of our virtual voice – OS volume is untouched.

In real reports it’s important to check instruction return code in sy-subrc.

I ommit this part just to cause reports more readable.

 

REPORT ztts_one.
TYPE-POOLS ole2.
DATA tts TYPE ole2_object.
CREATE OBJECT tts 'sapi.spvoice'.
SET PROPERTY OF tts: 'Rate'   = 0,   " from -10 to  10
                     'Volume' = 100. " from   0 to 100
CALL METHOD OF tts 'Speak' EXPORTING #1 = 'Indevya.com'.
FREE OBJECT tts.

 

Look at next two reports to see what else can be done…

 

Here report will tell us some info about today.

REPORT ztts_two.
TYPE-POOLS ole2.
DATA tts TYPE ole2_object.
CREATE OBJECT tts 'sapi.spvoice'.
CALL METHOD OF tts 'Speak': EXPORTING #1 = sy-datum,
                            EXPORTING #1 = sy-uzeit.
FREE OBJECT tts.

 

This report is combination of visual and sound progress indicator.

REPORT ztts_three.
TYPE-POOLS: ole2, abap.
DATA tts TYPE ole2_object.
PARAMETERS p_times TYPE i DEFAULT 1
CREATE OBJECT tts 'sapi.spvoice'.
START-OF-SELECTION.
  DO p_times TIMES.
    CALL FUNCTION 'PROGRESS_INDICATOR'
      EXPORTING
        i_text               = sy-index
        i_processed          = sy-index
        i_total              = p_times
        i_output_immediately = abap_true.
    CALL METHOD OF tts 'Speak': EXPORTING #1 = sy-index.
  ENDDO.
  FREE OBJECT tts.

 

You can find more details about SAPI on Microsoft’s MSDN (for example for win7 SAPI 5.4 ).

Published by

Peek Poke

PeekPoke is a programmer from the time he got his first computer - Atari 800XL.

One thought on “Is it even possible to use TTS in ABAP coding ?

Leave a Reply

Your email address will not be published. Required fields are marked *