Skip to Content
Ever wondered how would it look or feel if our ABAP programs speaks something. Great, right? I actually tried this after reading this blog. I used FreeTTS Speech project on source forge to accomplish my task. Before proceeding, let me tell you the program flow of the whole application(though small). I will first execute a java class file from ABAP and pass to this the contents which are to be spoken. This java code will actually save these contents onto a local file. Then I code a batch file on windows which in turn will execute another java program which in turn will read the contents from this local file and speak it out. Now without any other deviations lets start out work. First of all download the FreeTTS Speech Synthesis Engine from here. I downloaded the zip file onto my C drive and unzipped it. Then I set the classpath variable as shown in figure below. image The code of first java file which takes parameters and save that onto a local file looks like this: import java.io.*; public class write_string { public static void main(String args[]){ try { BufferedWriter out = new BufferedWriter(new FileWriter(“c:\\outfilename.txt”)); int i=0; while (i < args.length) { out.write(args[i]); out.write(” “); i++; } out.close(); } catch (IOException e) { } } } Note that the name of the output file is hard coded here. The second java file which reads this file and speak it up looks like this: /** * @author I039850 * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ import java.io.*; import com.sun.speech.freetts.Voice; import com.sun.speech.freetts.VoiceManager; public class TEST { public static void main(String[] args) { try { VoiceManager voiceManager = VoiceManager.getInstance(); Voice voice = voiceManager.getVoice(“kevin16”); voice.allocate(); BufferedReader in = new BufferedReader(new FileReader(“outfilename.txt”)); String str; while ((str = in.readLine()) != null) { voice.speak(str); } voice.deallocate(); } catch (Exception ex){ System.out.println( ex ); } } } The contents of the Windows batch file is: java TEST You must be wondering why I am using a batch file to execute a java program inside it. I could have called it directly from ABAP. Well when I was calling this java program directly(from ABAP), it wasnt playing anything for some god damn reason. So I played it well and called a batch file from ABAP which it turn executed the java class file. 🙂 My ABAP program looks like this: *&———————————————————————* *& Report ZEXECUTE *& *&———————————————————————* *& *& *&———————————————————————* REPORT ZEXECUTE. *message ‘SF’ number ’10’. data para type string. parameter mytext type objectname obligatory. *data mytext type string. para = ‘write_string’. CONCATENATE para mytext into para separated by space. CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE EXPORTING * DOCUMENT = ‘JAVA’ APPLICATION = ‘JAVA’ PARAMETER = para DEFAULT_DIRECTORY = ‘C:\’ * MAXIMIZED = MINIMIZED = ‘X’ SYNCHRONOUS = ‘WAIT’ OPERATION = ‘OPEN’ EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 BAD_PARAMETER = 3 FILE_NOT_FOUND = 4 PATH_NOT_FOUND = 5 FILE_EXTENSION_UNKNOWN = 6 ERROR_EXECUTE_FAILED = 7 SYNCHRONOUS_FAILED = 8 NOT_SUPPORTED_BY_GUI = 9 others = 10 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL METHOD CL_GUI_FRONTEND_SERVICES=>EXECUTE EXPORTING * DOCUMENT = ‘JAVA’ APPLICATION = ‘my’ * PARAMETER = ‘jinvoker’ DEFAULT_DIRECTORY = ‘C:\’ * MAXIMIZED = MINIMIZED = ‘X’ SYNCHRONOUS = ‘WAIT’ OPERATION = ‘OPEN’ EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 BAD_PARAMETER = 3 FILE_NOT_FOUND = 4 PATH_NOT_FOUND = 5 FILE_EXTENSION_UNKNOWN = 6 ERROR_EXECUTE_FAILED = 7 SYNCHRONOUS_FAILED = 8 NOT_SUPPORTED_BY_GUI = 9 others = 10 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. Write ‘Success’. I am using execute method of class CL_GUI_FRONTEND_SERVICES to execute executables on local machine or presentation server. Note that in the function module call, I have given default directory as C:\. Now when I executed this ABAP report, it prompted me for a value. I gave the value and pressed F8 and bingo, Kevin spoke up that “value”. Actually I feel that this small application and the blog which was written by Ignacio can be good starting point for SAP accessibility. And am now trying to extend this application such that whenever an error is poppped up, Kevin would speak it up. Btw Thanks Amit and Saurabh for helping me on Java front.
To report this post you need to login first.

17 Comments

You must be Logged on to comment or reply to a post.

      1. Amit Sharma
        Hay puru nice job,
        It’s great to see the extension you are working with ABAP, accessibility has always been in the discussion at SAP and your blog propose a way to address it.
        Nice job…..keep it up

        (0) 
  1. Alvaro Tejada Galindo
    Hi Puru:

    Haven’t test it…But after reading the code, I can see that is something really great…Thanx for sharing this -:D

    I’m not a Java fan…But this really makes me look a it on a different way -;)

    Greetings,

    Blag.

    (0) 
  2. Ignacio Hernández
    Your approach is very interesting.
    I think in a “ERP event, Sound File generation and Message delivery” scenario.
    We can catch the business event at ERP (for instance a new sales order notification), use the engine to generate a voice message file (it can be a wav file) and send it by mail (to a mobile device ?).
    We are going to pick up our cell phone and listen “You have a new sales order for a million dollar by the biggest customer”…
    Best,
    Ignacio.
    (0) 
      1. Ignacio Hernández
        this one ?
        listening Shai Agassi key note in Las Vegas, he showed a holiday approval process using voice, and in some way a think it to a sales order notification process.
        If you have some Java/Abap integration initiative or a Netweaver focus Abap development initiative you are welcome to participate at Open Innovation Call, a community open projects effort.
        Best,
        Ignacio.
        (0) 
  3. Anonymous
    Although i have not tested this , but the best part is the innovative idea that you have used and also how the way you manged to integrate the ABAP with java
    (0) 
  4. Anonymous
    Good Thinking Man!
    This CL_FRONTEND_SERVICES provides quite a lot of flexibility in terms of interacting with the local m/c.
    B/W, to execute java classes, run JVM as an application and provide it with parameters like class name, class path, other options etc in the form of a string.
    (0) 

Leave a Reply